I have obtained the script below from the Web and I have amended it for my purpose:
$report = @()
foreach ($dc in Get-Datacenter) {
foreach ($cluster in Get-Cluster -Location $dc){
$vms = Get-view -ViewType VirtualMachine
foreach ($vm in $vms){
$info = "" | select Datacenter, Name, ToolsStatus, NumCpu, MemoryMB, guestos, @{N='IPAddr';E={[string]::Join(',',$vm.Guest.net.IPAddress)}} | sort Name
$info.datacenter = $dc.name
$info.Name = $vm.name
$info.toolsstatus = $vm.guest.toolsstatus
$info.NumCpu = $vm.Summary.config.NumCpu
$info.MemoryMB = $vm.Summary.config.memorySizeMB
$info.guestos = $vm.guest.guestfullname
$report += $info
}
}
}
$report | export-csv "\Report.csv" -NoTypeInformation
I would now like to amend the script to add the Datastore that each VM is stored on but I cannot seem to pipe that information into the script. I have found another script which gets the datastore name but I cannot figure out how to configure the script above to include it:
Get-View -ViewType "VirtualMachine" -Property "Name", "Config.DatastoreUrl" | Select-Object -Property Name, @{N="DataStore";E={$_.Config.DatastoreUrl | %{$_.Name}}}
Please could you help?