VMware Cloud Community
esxi1979
Expert
Expert
Jump to solution

Get-VM | Get-VIEvent -- How can i get folder info ?

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... 

1 Solution

Accepted Solutions
kunaludapi
Expert
Expert
Jump to solution

@{N=”Folder”; E={(Get-VM $_.VM.name).folder}}

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

View solution in original post

4 Replies
kunaludapi
Expert
Expert
Jump to solution

@{N=”Folder”; E={(Get-VM $_.VM.name).folder}}

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
esxi1979
Expert
Expert
Jump to solution

Thanks !

0 Kudos
esxi1979
Expert
Expert
Jump to solution

Hi ,

Any way of getting the Parent folder  as well (in case the vm is in sub-folder) ?

Thanks

0 Kudos
Nerenther
Contributor
Contributor
Jump to solution

@{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>

0 Kudos