My script for getting vm created info works well, But when i tried to add coloum "folder" it is not workig.
Get-VM | Get-VIEvent -Start (Get-Date).adddays(-2) | `
where { $_.Gettype().Name -eq "VmCreatedEvent" -} | `
select @{N=”VMname”; E={$_.Vm.Name}},
@{N=”Host”; E={$_.Host.Name}}
..
ConvertTo-Html ...
How can i add "folder Name" in that ? I tried,
@{N="Folder";E={$_.vm.Folder.Name}}
But it gives blank info...
@{N=”Folder”; E={(Get-VM $_.VM.name).folder}}
@{N=”Folder”; E={(Get-VM $_.VM.name).folder}}
Thanks !
Hi ,
Any way of getting the Parent folder as well (in case the vm is in sub-folder) ?
Thanks
@{N=”Folder”; E={"$((get-folder (Get-VM $_.VM.name).folder).Parent)\$((get-vm $_.vm.name).folder)"}}
This will work nicely if the vm is in a subfolder of a folder that is located at root. If the vm is located in a folder directly under root it will output vm\<foldername>