Tried modifying LucD's code but to no avail:
$report = @()
$inherited = $true
$authMgr = Get-View AuthorizationManager
$roles = @{}
foreach($role in $authMgr.RoleList){
$roles[http://$role.RoleId|http://$role.RoleId] = $role.Name
}
Get-DataCenter -Name "DC_name" {
$exist = Get-VIObjectByVIView -MORef $_.MoRef -ErrorAction SilentlyContinue
if($exist -ne $null){
$current = Get-View $_.Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)
$permissions = $authMgr.RetrieveEntityPermissions($_.MoRef, $inherited)
if($permissions.Length -ne 0){
foreach($perm in $permissions){
$row = "" | select Name, Path, Principal, Group, Role, DefinedIn
$row.Name = $_.Name
$row.Path = $path
$row.Principal = $perm.Principal
$row.Group = $perm.Group
$row.Role = $roles[http://$perm.RoleId|http://$perm.RoleId]
$row.DefinedIn = (Get-View -Id $perm.Entity).Name
$report += $row
}
}
else{
$row = "" | select Name, Path, Princiapl, Group
$row.Name = $_.Name
$row.Path = $path
$report += $row
}
}
}
Works for me.
Where do you run this from ? (PowerCLI prompt, PowerGui, Vesi...)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try the attached script.
I suspect you want to report the permissions for a datacenter and all its child objects ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes. I get the following error when I run the script:
The argument cannot be null or empty.
At :line:52 char:31
+ Get-DataCenter -Name "DC_name" | % <<<< {
PG script editor
Omit
-Name "DC_name"
There was a Get-View missing after the Get-Datacenter cmdlet.
Try this script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
still getting the same error
nope...still getting the same error.
Could you give me the complete error message (with the line number) and when using the script from my last attached file ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The argument cannot be null or empty.
At :line:52 char:52
+ Get-DataCenter -Name "DC_Name" | Get-View | % <<<< {
You do have a datacenter that is called "DC_Name" ?
Does this return anything ?
Get-Datacenter -Name "DC_Name"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes to both questions...
ustomFields : {AutoWM CR, BarCode, Site Wide AutoWM CR}
Id : Datacenter-datacenter-134
Name : DC_Name
Judging from the line number in the error message there are other lines before the line that contains the Get-Datacenter cmdlet.
Is it possible to attach the complete script ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Works for me.
Where do you run this from ? (PowerCLI prompt, PowerGui, Vesi...)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
powergui...I'm going to try it from the ps prompt
OK...here's the results after running the script from the ps prompt:
I got some output to the csv file but there was a slightly differrent error this time.
Get-View ; the argument cannot be null or empty.
At C:\windows\system32\WindowsPowerShell\v1.0\test.ps1:59 char:23
$current = Get-View <<<< $current.parent
You must be encountering a node with a parent that is equal to $null.
Which is strange since the loop (do while) is stopping on that condition.
You could perhaps insert a Write-Host $path just before the statement.
That would allow you to see where it goes wrong.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference