Hi,
I carried out this script to have the list of vms for each esx, I would also have to display the number of vms by esx too,
but a problem appears during the execution,
no problem without line 17, but when I insert line 17 I have an error
Can you help, please
thank you
Get-Module -Name VMware* -ListAvailable | Import-Module
$user = 'root'
$pswd = Read-Host -Prompt "Please enter your Password:"
$report = @()
Import-Csv -Path C:\Scripts\Tags_patch\ressources\List_test.csv -UseCulture | %{
$srv = Connect-VIServer -Server $_.ESXName -User $user -Password $pswd
$report += (Get-VM -Server $srv |
Select @{N='VMHost';E={$_.VMHost.Name}},
@{N=“NumVM“;E={($_ | Get-VM).Count}},
Name,PowerState,
@{n="HardDiskSizeGB"; E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
@{N='GuestOS';E={$_.Guest.OSFullName}},
@{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}},
@{N='IP';E={$_.Guest.IPAddress -join '|'}})
Disconnect-VIServer -Server $srv -Confirm:$false
}
$report | Export-Csv -Path C:\Scripts\Tags_patch\resultats\test.csv -NoTypeInformation -UseCulture
The pipeline variable does contain a single VM where you use it.
Try like this
$pswd = Read-Host -Prompt "Please enter your Password:"
$report = @()
Import-Csv -Path C:\Scripts\Tags_patch\ressources\List_test.csv -UseCulture | %{
$srv = Connect-VIServer -Server $_.ESXName -User $user -Password $pswd
$vms = Get-VM -Server $srv
$report += $vms | Select @{N='VMHost';E={$_.VMHost.Name}},
@{N=“NumVM“;E={$vms.Count}},
Name,PowerState,
@{n="HardDiskSizeGB"; E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
@{N='GuestOS';E={$_.Guest.OSFullName}},
@{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}},
@{N='IP';E={$_.Guest.IPAddress -join '|'}}
Disconnect-VIServer -Server $srv -Confirm:$false
}
$report | Export-Csv -Path C:\Scripts\Tags_patch\resultats\test.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It would help if you show the error.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The pipeline variable does contain a single VM where you use it.
Try like this
$pswd = Read-Host -Prompt "Please enter your Password:"
$report = @()
Import-Csv -Path C:\Scripts\Tags_patch\ressources\List_test.csv -UseCulture | %{
$srv = Connect-VIServer -Server $_.ESXName -User $user -Password $pswd
$vms = Get-VM -Server $srv
$report += $vms | Select @{N='VMHost';E={$_.VMHost.Name}},
@{N=“NumVM“;E={$vms.Count}},
Name,PowerState,
@{n="HardDiskSizeGB"; E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
@{N='GuestOS';E={$_.Guest.OSFullName}},
@{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}},
@{N='IP';E={$_.Guest.IPAddress -join '|'}}
Disconnect-VIServer -Server $srv -Confirm:$false
}
$report | Export-Csv -Path C:\Scripts\Tags_patch\resultats\test.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i have an error on result :
C:\Scripts\Tags_patch\programmes\CMDBTags> C:\Scripts\Tags_patch\programmes\CMDBTags\test.ps1
At C:\Scripts\Tags_patch\programmes\CMDBTags\test.ps1:9 char:80
+ ... -Path C:\Scripts\Tags_patch\ressources\List_test.csv -UseCulture | %{
+ ~
Missing closing '}' in statement block or type definition.
At C:\Scripts\Tags_patch\programmes\CMDBTags\test.ps1:27 char:51
+ @{N='IP';E={$_.Guest.IPAddress -join '|'}})
+ ~
Unexpected token ')' in expression or statement.
At C:\Scripts\Tags_patch\programmes\CMDBTags\test.ps1:31 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace
I had a typo, code above is ocrrected
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thank you so much