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
With a little recursion you can go a long way
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
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
This is great 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
Hi,
you can use my function to get that entire folder path.
Let me know if you have problems to put it in your script
With a little recursion you can go a long way
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
Lucd - that worked great. One last thing is possible to get the security from the Folder?
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
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
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
That worked !!! Thank you so much !