Hello,
Kindly seeking help in combine the scripts in the attached text file. We have a requirement to find the below details of a collection of VMs. VM Names are in a text file.
VMName, VMHost, ClusterName, Datastore Location.
Also we need to have the list is sorted with VMNames
Thanks in Advance
Rajesh
Is there any way to use autosize, as the long datastore names trunctes.
Try Autosize
Get-VM (Get-content c:\temp\vms.txt) | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}} | FT -AutoSize
Try wrapping?
Get-VM (Get-content c:\temp\vms.txt) | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}} | FT -Wrap
If possible, can we use sort-object with VM Names ?
Yep, just pipe to Sort-Object
Get-VM (Get-content c:\temp\vms.txt) | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}} | Sort VMName
Also, can we use export-csv to export the out put to excel ?
Yep, Just pipe to Export-CSV
Get-VM (Get-content c:\temp\vms.txt) | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}} | Export-CSV -NoTypeInformation C:\temp\VMExport.csv
Something like this?
$vms = Get-content vms.txt
Get-VM $vms | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}}
Great, its working fine.. Thanks for it.
Just 3 more queries,
Is there any way to use autosize, as the long datastore names trunctes.
If possible, can we use sort-object with VM Names ?
Also, can we use export-csv to export the out put to excel ?
Thanks in advance.
Rajesh
Is there any way to use autosize, as the long datastore names trunctes.
Try Autosize
Get-VM (Get-content c:\temp\vms.txt) | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}} | FT -AutoSize
Try wrapping?
Get-VM (Get-content c:\temp\vms.txt) | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}} | FT -Wrap
If possible, can we use sort-object with VM Names ?
Yep, just pipe to Sort-Object
Get-VM (Get-content c:\temp\vms.txt) | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}} | Sort VMName
Also, can we use export-csv to export the out put to excel ?
Yep, Just pipe to Export-CSV
Get-VM (Get-content c:\temp\vms.txt) | Select-Object -Property @{Name='VMName';Expression={$_.Name}},VMHost,@{Name='ClusterName';Expression={$_.VMHost.Parent}}, @{"Name"="Datastore"; expression={($_.DatastoreIDList | %{(Get-View -Property Name -Id $_).Name}) -join ", "}} | Export-CSV -NoTypeInformation C:\temp\VMExport.csv
Working perfect.
Thanks for the efforts.
Regards
Rajesh