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.
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
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
Thank you. Worked perfectly