No_Way
Enthusiast
Enthusiast

Create Guest OS list by OS

Hi

I am trying to get a list of Guest OS VMs and then change something.

I see some examples where I can use the Get-VM and also Get-View for both cases.

Example:

get-vm | Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}

or just

Get-View -ViewType VirtualMachine -Property Name,Config.GuestFullName  | %{

    New-Object -TypeName PSObject -Property @{

        Name = $_.Name

        GuestOS = $_.Config.GuestFullName

    }

} | Select Name, GuestOS

Using a filter( -Filter @{"Config.GuestFullName" = "Windows*"} ) or not to list the proper Guest OS type.

But what I need, and I am not able to do is, using with the Get-View or Get-VM, removing the filter, and in a foreach check witch VM have Linux or Windows, then do an action after found the type of Guest OS.

For example, add a TAG like this: New-TagCategory –Name "Windows" -Description "VMs System Operation TAG" –Cardinality single –EntityType VirtualMachine

I can run everything individually and works fine, but my problem is to put everything in only script and with a condition for each type of Guest OS

Thanks in advance for any help.

NW

Reply
0 Kudos