Hi,
I have been parsing together some scripts trying to build a report that will show me the full WIM details for windows machines, else the Operating System default for the non-windows machines.
I have this:
Get-VM |Sort Name |Select Name, NumCPU, @{N=“OperatingSystem“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select Caption).Caption}}, @{N=“ServicePack“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select CSDVersion).CSDVersion} -Enable} | Export-Csv "C:\scripts\Output\ostest1.csv" -NoTypeInformation
This gets me the Windows names, but i'm not sure how to say if Operating System contains Microsoft, run the Get-WimObject commands, else just report the OS as listed in Get VM
Any help would be appreciated!
Try something like this
Get-VM |Sort Name |
Select Name, NumCPU,
@{N=“OperatingSystem“;E={
if($_.ExtensionData.summary.config.guestfullname -match "Windows"){
Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select -ExpandProperty Caption
}
else{
$_.ExtensionData.summary.config.guestfullname
}
}},
@{N=“ServicePack“;E={
if($_.ExtensionData.summary.config.guestfullname -match "Windows"){
Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select -ExpandProperty CSDVersion
}
else{"na"}}} |
Export-Csv "C:\scripts\Output\ostest1.csv" -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Get-VM | Where-Object {$_.ExtensionData.summary.config.guestfullname -match "Windows"} | Sort Name |Select Name, NumCPU, @{N=“OperatingSystem“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select Caption).Caption}}, @{N=“ServicePack“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select CSDVersion).CSDVersion} -Enable} | Export-Csv "C:\scripts\Output\ostest1.csv" -NoTypeInformation
Try something like this
Get-VM |Sort Name |
Select Name, NumCPU,
@{N=“OperatingSystem“;E={
if($_.ExtensionData.summary.config.guestfullname -match "Windows"){
Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select -ExpandProperty Caption
}
else{
$_.ExtensionData.summary.config.guestfullname
}
}},
@{N=“ServicePack“;E={
if($_.ExtensionData.summary.config.guestfullname -match "Windows"){
Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select -ExpandProperty CSDVersion
}
else{"na"}}} |
Export-Csv "C:\scripts\Output\ostest1.csv" -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference