Hello All,
I've got a seemingly simple task, trying to incorporate the Config.Files.VMPath property of get-view into my existing script, which is also using the get-view method to extract vm properties. The issue seems to be that the initial script is using a select statement:
$Report = @()
$VMs = Get-VM -location $ResourcePool
$Datastores = Get-Datastore | select Name, Id
$date = Get-Date -format M
$filename = "$ResourcePool $date VM IP and Datastore.csv"ForEach ($VM in $VMs) {
$VMView = $VM | Get-View
$VMInfo = {} | Select VMName,IPAddress, VMXlocation, Datastore
$VMInfo.VMName = $vm.name
$VMInfo.IPAddress = $vm.Guest.IPAddress[0]
$VMInfo.VMXlocation = $vm.Config.Files.VmPathName
$VMInfo.Datastore = ($Datastores | where {$_.ID -match (($vmview.Datastore | Select -First 1) | Select Value).Value} | Select Name).Name
$Report += $VMInfo
}
$report | Export-Csv $filename
The VMXlocation piece returns nothing. I can run "Get-View -ViewType VirtuaMachine |%{$_.Config.Files.VMPathName" at a prompt and it works fine. Obviously the config.files.vmpath property doesn't require a select statement or something along those lines, but I'm not good enough to figure out how to make it work. Any help is greatly appreciated.
Dave
Try changing that line to
$VMInfo.VMXlocation = $vm.ExtensionData.Config.Files.VmPathName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try changing that line to
$VMInfo.VMXlocation = $vm.ExtensionData.Config.Files.VmPathName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Bingo. Thank you, Sir!! I'm looking at some other scripts of yours to expand upon the output from this to then un-register the VM and then re-register in a new datacenter (same vCenter) along with providing the resource pool. I will also need to preserve the Annotations and custom annotations. A nice scripting project. Piece of cake for you, I'm sure.
Thanks again!