VMware Cloud Community
rbrads
Enthusiast
Enthusiast
Jump to solution

Using PowerCli to display vcentre folder location

Hi,

I have justed started using Power Cli today. I managed to get some info from the internet but im having a problem with the script im sure its simple but at this stage i dont know enough about it.

Basically I want thescript to output to a csv file with the Virtual Machine Name, Datastore, Host and its VCentre Folder Location.

Everything is getting populated except the get-folder colum which im hoping will show the VCentre Folder Location

Get-VM | Select Name, @{N="Cluster";E={Get-Cluster -VM $_}}, `
@{N="ESX Host";E={Get-VMHost -VM $_}}, `
@{N="VICont";E={Get-Folder -VM $_}}, `
@{N="Datastore";E={Get-Datastore -VM $_}} | `
Export-Csv -NoTypeInformation C:\VM_CLuster_Host_Datastore1.csv

Many Thanks

Ryan

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

With a little recursion you can go a long way Smiley Wink

Get-VM | Select-Object -property Name, 
@{N="Cluster";E={$_.VMhost.Parent}},
@{N="ESX Host";E={$_.VMHost}},
@{N="VICont";E={   $nodes = @()   $obj = $_.ExtensionData
 
while ($obj.Parent){     $obj = Get-View $obj.Parent
   
if("Datacenters","vm" -notcontains $obj.Name){       $nodes += $obj.Name
    }   }   [
string]::Join('/',$nodes[($nodes.Count - 1)..0])}},
@{N="Datastore";E={Get-Datastore -VM $_}} | Export-Csv -NoTypeInformation C:\VM_CLuster_Host_Datastore1.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
9 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Ryan,

the next script shows the folder as well. I also made some other improvements.

Get-VM | Select-Object -property Name, @{N="Cluster";E={$_.VMhost.Parent}}, `
@{N="ESX Host";E={$_.VMHost}}, `
@{N="VICont";E={$_.Folder}}, `
@{N="Datastore";E={Get-Datastore -VM $_}} | `
Export-Csv -NoTypeInformation C:\VM_CLuster_Host_Datastore1.csv

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
rbrads
Enthusiast
Enthusiast
Jump to solution

This is great Smiley Happy but is it posibble to include the entire folder location as it only gives the last folder. e.g If i have two master folder called Production & Development and the next folder each of those is called Tier 1  the spreadsheet only shows the vm location as Tier 1 and not Production\Tier1 or Development\Tier1. Is it possible to get the full path ?

Thanks

0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

Hi,

you can use my function to get that entire folder path.

http://psvmware.wordpress.com/2012/09/14/get-vmfolderpath-to-check-in-which-vm-folder-our-vm-resides...

Let me know if you have problems to put it in your script

--- @blog https://grzegorzkulikowski.info
LucD
Leadership
Leadership
Jump to solution

With a little recursion you can go a long way Smiley Wink

Get-VM | Select-Object -property Name, 
@{N="Cluster";E={$_.VMhost.Parent}},
@{N="ESX Host";E={$_.VMHost}},
@{N="VICont";E={   $nodes = @()   $obj = $_.ExtensionData
 
while ($obj.Parent){     $obj = Get-View $obj.Parent
   
if("Datacenters","vm" -notcontains $obj.Name){       $nodes += $obj.Name
    }   }   [
string]::Join('/',$nodes[($nodes.Count - 1)..0])}},
@{N="Datastore";E={Get-Datastore -VM $_}} | Export-Csv -NoTypeInformation C:\VM_CLuster_Host_Datastore1.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
rbrads
Enthusiast
Enthusiast
Jump to solution

Lucd - that worked great. One last thing Smiley Happy is possible to get the security from the Folder?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, we can use the Get-ViPermission for that.

But what do you want to report upon, the principal(s), the role(s)....

And how do you want to present that in your report ? There can be multiple permissions on a folder.

And what about the inherited permssions ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
rbrads
Enthusiast
Enthusiast
Jump to solution

Id like to get the permissions from the last folder in the chain. e.g if the folder is string is /ESXi_Venom/Assigned/CTM/Servers id like a list off al the users that have permission to Servers Folder. That should show all the ID's weather they are inheritted or added directly. If that makes sense

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure does, try something like this

Get-VM | Select-Object -property Name, 
@{N="Cluster";E={$_.VMhost.Parent}}, 
@
{N="ESX Host";E={$_.VMHost}},
@
{N="VICont";E={   $nodes = @()   $obj = $_.ExtensionData  while ($obj.Parent){     $obj = Get-View $obj.Parent
   
if("Datacenters","vm" -notcontains $obj.Name){       $nodes += $obj.Name
    }   }   [
string]::Join('/',$nodes[($nodes.Count - 1)..0])}},
@
{N="Datastore";E={Get-Datastore -VM $_}},
@{N="Authorised users on Parent";E={   [string]::Join(',',(Get-VIPermission -Entity $_.Folder | %{$_.Principal}))}} |
Export-Csv
-NoTypeInformation C:\VM_CLuster_Host_Datastore1.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
rbrads
Enthusiast
Enthusiast
Jump to solution

That worked !!! Thank you so much ! Smiley Happy Smiley Happy Smiley Happy

0 Kudos