VMware Cloud Community
Jazzaa71
Contributor
Contributor
Jump to solution

How to get information on certain vm's

Hello,

I'm trying to figure out how I can scan a csv file which will have servers inside that require operating system checking again guest os and running os.

This is what I have so far and it appears to work just fine, I just require another line that will make it scan for servers specified inside the csv file.

Get-View -ViewType “VirtualMachine” -Property @(“Name”, “Config.GuestFullName”, “Guest.GuestFullName”) |Where-Object {($_.Config.GuestFullName -ne $_.Guest.GuestFullName) -and ($_.Guest.GuestFullName -ne $null)} | Select-Object -Property Name, @{N=”Configured OS”;E={$_.Config.GuestFullName}}, @{N=”Running OS”;E={$_.Guest.GuestFullName}} | Export-Csv c:\VMOSReport.csv -NoTypeInformation -UseCulture

The line above is not my own work and sourced from the web.

Thank you.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do something like this.

It reads all the names from the CSV file, and the puts them together in a string, separated with a '|'

In the Get-View cmdlet you can use a Filter parameter, it accepts a RegEx expression, hence the format of the string.

The script assumes the CSV lookes like this

ServerName

Name1

Name2

$names = (Import-Csv .\names.csv -UseCulture | select -ExpandProperty ServerName) -join '|'

Get-View -ViewType “VirtualMachine” -Property @(“Name”, “Config.GuestFullName”, “Guest.GuestFullName”) -Filter @{'Name'=$names} |

Where-Object {($_.Config.GuestFullName -ne $_.Guest.GuestFullName) -and ($_.Guest.GuestFullName -ne $null)} |

Select-Object -Property Name, @{N=”Configured OS”;E={$_.Config.GuestFullName}}, @{N=”Running OS”;E={$_.Guest.GuestFullName}} |

Export-Csv c:\VMOSReport.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You can do something like this.

It reads all the names from the CSV file, and the puts them together in a string, separated with a '|'

In the Get-View cmdlet you can use a Filter parameter, it accepts a RegEx expression, hence the format of the string.

The script assumes the CSV lookes like this

ServerName

Name1

Name2

$names = (Import-Csv .\names.csv -UseCulture | select -ExpandProperty ServerName) -join '|'

Get-View -ViewType “VirtualMachine” -Property @(“Name”, “Config.GuestFullName”, “Guest.GuestFullName”) -Filter @{'Name'=$names} |

Where-Object {($_.Config.GuestFullName -ne $_.Guest.GuestFullName) -and ($_.Guest.GuestFullName -ne $null)} |

Select-Object -Property Name, @{N=”Configured OS”;E={$_.Config.GuestFullName}}, @{N=”Running OS”;E={$_.Guest.GuestFullName}} |

Export-Csv c:\VMOSReport.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Jazzaa71
Contributor
Contributor
Jump to solution

Thank you. Worked perfectly

0 Kudos