Having a hard time here...how do i return results for just linux and OS's called "Other" instead of just all OSs. I have the script below:
get-vm | Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}} | Export-CSV -NoTypeInformation C:\Users\iaasadmin\Desktop\getvms.csv
Any ideas to add the filter to just return Linux and Other OSs?
Thank you
Try like this
Get-VM |
where{$_.ExtensionData.Config.GuestFullname -notmatch "win"} |
Select Name,
@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},
@{N="Running OS";E={$_.Guest.OsFullName}},
@{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}},
@{N="disktype";E={(Get-Harddisk $_).Storageformat}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Modify your query as given below:
get-vm | Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}} | Where { ($_."Configured OS").contains("Other") -or ($_."Configured OS").contains("Linux") } | Export-CSV -NoTypeInformation C:\Users\iaasadmin\Desktop\getvms.csv
I agree with Luc. Some linux distributions do not list their OS correctly, whereas I haven't run across a situation where Windows OS is incorrect. I will typically use something like the below to operate on windows machines. If you're looking to gather non-windows you can just negate the if clause, or use an else.
foreach($objCluster in Get-Cluster){
foreach ($objvm in $($objCluster|get-vm)){
if($objvm.guestid.contains("windows")){
#### windows actions or data collection goes here
}else{
### non-windows actions or data collection goes here
}
}
}
This was exactly what I needed, LucD! I removed some of the parameters, but it was perfect. Thanks, as always!