Hi,
How can I modify the following code so that the results are on separate lines and cells for each virtual machine?
Get-Datastore |
Where-Object {$_.Name -notMatch ("ESX|Datastore1")} | %{
New-Object PSObject -Property @{ClusterName = (Get-DatastoreCluster -Datastore $_ | Select -ExpandProperty Name)
Name = $_.name
Folder = (Get-VM -Datastore $_ | Select -ExpandProperty folder)
VMs = (Get-VM -Datastore $_ | Select -ExpandProperty Name)
}
}
I'm guessing that a foreach loop can be fit in somewhere?
Thanks
Below is the code you can use data to export to excel.
Get-Datastore |
Where-Object {$_.Name -Notmatch ("ESX|Datastore1")} | %{
New-Object PSObject -Property @{ClusterName = (Get-DatastoreCluster -Datastore $_ | Select -ExpandProperty Name)
Name = $_.name
Folder = ((Get-VM -Datastore $_ | Select -ExpandProperty folder) -join "`n")
VMs = ((Get-VM -Datastore $_ | Select -ExpandProperty Name) -join "`n")
}
}
Below is the code you can use data to export to excel.
Get-Datastore |
Where-Object {$_.Name -Notmatch ("ESX|Datastore1")} | %{
New-Object PSObject -Property @{ClusterName = (Get-DatastoreCluster -Datastore $_ | Select -ExpandProperty Name)
Name = $_.name
Folder = ((Get-VM -Datastore $_ | Select -ExpandProperty folder) -join "`n")
VMs = ((Get-VM -Datastore $_ | Select -ExpandProperty Name) -join "`n")
}
}
Hi Kunai,
Thanks for your response but when I tired to export the data to a csv file I get the following message
"An empty pipe element is not allowed" Do I tried adding the Select-Object cmdlet:
Select-Object -Property ClusterName, DatastoreName, Folder, VM
but when I pipe to export-csv the data isn't getting sent to the csv file.
What I'm trying to accomplish is export the data in a csv file like this:
CusterName DataStoreName Folder VMs
I am not getting any error while running. (Running against local datastore, don't have shared)
I was able to get the code to work but I need a separate line for both the folder and VMs column instead of joining the output.
Thanks