PowerCLI Get VMs those fit some conditions

0

I'm trying to get our some Linux distros from vCenter by using PowerCLI. But I don't want to get Appliance VMs. So I have 2 different successful PowerCLI scripts those can find these machines. I want merge these scripts but I'm new on PowerCLI and it's syntax.

I'm sharing these scripts at below:


Non-Appliance List:

Get-VM | `
Get-Annotation | `
Where-Object {$_.name -eq "Appliance"} | `
Where-Object {$_.value -eq 'No'} | `
Export-Csv C:\Users\me\Documents\non-appliance-list.csv -NoTypeInformation -UseCulture

Linux List:

Get-View -Property @("Name", "Config.GuestFullName","Guest.GuestFullName") | `
Select -Property Name, @{N="COS";E={$_.Config.GuestFullName}}, @{N="ROS";E={$_.Guest.GuestFullName}} | `
Where-Object ({$_.ROS -like 'Centos*' -or $_.ROS -like 'Suse*' -or $_.ROS -like 'Ubuntu*'}) | `    
Select AnnotatedEntity,Name,Value | `
Export-Csv C:\Users\me\Documents\linux-list.csv -NoTypeInformation -UseCulture

Script I imagined but doesn't worked:

Get-VM | `
Get-Annotation | `
Where-Object {$_.name -eq "Appliance"} | `
Where-Object {$_.value -eq 'No'} | `
Get-View -Property @("Name", "Config.GuestFullName","Guest.GuestFullName") | `
Select -Property Name, @{N="COS";E={$_.Config.GuestFullName}}, @{N="ROS";E={$_.Guest.GuestFullName}} | `
Where-Object ({$_.ROS -like 'Centos*' -or $_.ROS -like 'Suse*' -or $_.ROS -like 'Ubuntu*'}) | `    
Select AnnotatedEntity,Name,Value | `
Export-Csv C:\Users\me\Documents\linux--list.csv -NoTypeInformation -UseCulture

Maybe It has been a XY-Question. If you have a better way to get Linux VMs those are not appliance, you can say me this method.

Gefolge

Posted 2018-11-16T06:18:19.823

Reputation: 555

Answers

0

I added a variable named "vmlist" and this variable contains machines that are Linux. So now, $vmlist = SecondScript. And then I eliminated appliances from this list with other script. The final script is below:

$vmlist=(Get-VM | `
Get-View -Property @("Name", "Config.GuestFullName","Guest.GuestFullName") | `
Select -Property Name, @{N="COS";E={$_.Config.GuestFullName}}, @{N="ROS";E= {$_.Guest.GuestFullName}} | `
Where-Object ({$_.ROS -like 'Centos*' -or $_.ROS -like 'RedHat*' -or $_.ROS -like 'Ubuntu*' -or $_.ROS -like 'Suse*'}))

Get-VM $vmlist.name | `
Get-Annotation | `                                                                              
Where-Object {$_.name -eq "Appliance"} | Where-Object {$_.value -eq 'No'} | `
Export-Csv C:\Users\myuser\Documents\Scripts\Outputs\linux-list.csv -NoTypeInformation -UseCulture      

Gefolge

Posted 2018-11-16T06:18:19.823

Reputation: 555