Hi all,
I'm working on the below script to get all the VMs where the name contains "LB" and the guest Os is like "Linux":
$Today = get-date -format dd-MMMM-yy
$outputfile = "C:\Users\user.name\Desktop\LB-report-$Today.csv"
$vcenters = Get-Content vcenters.txt
$credential = Get-Credential -Message "Enter vCenter Credentials."
foreach ($vcenter in $vcenters){
Write-Output "connecting to vcenter" $vcenter
Connect-VIServer $vcenter -Credential $credential
}
Get-VM |
Select Name,PowerState,
@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},
@{N='VMHost';E={$_.VMHost.Name}},
@{N="vCenter";E={$_.Uid.Split('@')[1].Split(':')[0]}} |
Where-Object {($_.name -Like "*lb*") -and ($_.ExtensionData.Config.GuestFullname -Like "*Linux*")} |
Sort-Object Name, PowerState, Configured OS, VMHost, vCenter | Export-Csv $outputfile -NoTypeInformation
The thing is that the outut file is coming out empty, I know the issue could be in the "where-object" but not sure how to get it to work. Any idea?
Your Where-clause should come higher up in the pipeline construction.
The ExtensionData property is not available anymore after the Select-Object
Select Name,PowerState,
@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},
@{N='VMHost';E={$_.VMHost.Name}},
@{N="vCenter";E={$_.Uid.Split('@')[1].Split(':')[0]}} |
Sort-Object Name, PowerState, Configured OS, VMHost, vCenter |
Export-Csv $outputfile -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Your Where-clause should come higher up in the pipeline construction.
The ExtensionData property is not available anymore after the Select-Object
Select Name,PowerState,
@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},
@{N='VMHost';E={$_.VMHost.Name}},
@{N="vCenter";E={$_.Uid.Split('@')[1].Split(':')[0]}} |
Sort-Object Name, PowerState, Configured OS, VMHost, vCenter |
Export-Csv $outputfile -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
many thanks again mate, it worked