VMware Cloud Community
RAJESH3311
Enthusiast
Enthusiast
Jump to solution

Host, Cluster and Datastore Details

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

1 Solution

Accepted Solutions
sneddo
Hot Shot
Hot Shot
Jump to solution

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

View solution in original post

4 Replies
sneddo
Hot Shot
Hot Shot
Jump to solution

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 ", "}}

0 Kudos
RAJESH3311
Enthusiast
Enthusiast
Jump to solution

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

0 Kudos
sneddo
Hot Shot
Hot Shot
Jump to solution

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

RAJESH3311
Enthusiast
Enthusiast
Jump to solution

Working perfect.

Thanks for the efforts.

Regards

Rajesh

0 Kudos