I am a newbie to Powershell, Please help, as I am getting below error while running the script
Get-VM sql01 | Select Name, PowerState,
@{N="IP Address";E={@($_.guest.IPAddress[0])}}, `
@{N="Cluster";E={Get-Cluster -VM $_}}, `
@{N="ESX Host";E={Get-VMHost -VM $_}}, `
@{N="Folder";E={$_.Folder.Name}}, `
@{N="Datastore";E={Get-Datastore -VM $_}} | `
@{N="Disk Size";E={Get-HardDisk -VM $_ | Measure-Object -Property CapacityGB -Sum | Select -ExpandProperty Sum}} | `
Export-Csv -NoTypeInformation C:\VM.csv
I am getting the below error, please help
At C:\VM.ps1:7 char:1
+ @{N="Disk Size";E={Get-HardDisk -VM $_ | Measure-Object -Property CapacityGB -Su ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
Try like this
There was an extra pipe symbol on line 6.
No need to have a tick mark when the line ends with a comma or pipe symbol.
Get-VM sql01 | Select Name, PowerState,
@{N="IP Address";E={@($_.guest.IPAddress[0])}},
@{N="Cluster";E={Get-Cluster -VM $_}},
@{N="ESX Host";E={Get-VMHost -VM $_}},
@{N="Folder";E={$_.Folder.Name}},
@{N="Datastore";E={Get-Datastore -VM $_}},
@{N="Disk Size";E={Get-HardDisk -VM $_ | Measure-Object -Property CapacityGB -Sum | Select -ExpandProperty Sum}} |
Export-Csv -NoTypeInformation C:\VM.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot for your quick reply.
I would like to list Harddisks and RDM`s along with its size. how do I get ?
Please help.