VMware Cloud Community
mario_981
Enthusiast
Enthusiast

Folder Permissions

I am trying to obtain folder permissions of datacenter type folder in VCenter and trying to export it onto csv.

Any lead how to do this is much appreciated.

0 Kudos
10 Replies
LucD
Leadership
Leadership

Try something like this

Get-Folder -Type Datacenter |

   Get-VIPermission |

   Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

0 Kudos
mario_981
Enthusiast
Enthusiast

Thanks I wrote something like this - But I still have one more doubt

Get-Folder -Type Datacenter | Get-VIPermission | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

foreach($folder in Get-Folder -Type Datacenter)

{

    foreach ($dc in Get-Datacenter -Location $folder)

    {    

// How can I get permissions of each datacenter for a particular folder and export it to csv            

    }

}

0 Kudos
LucD
Leadership
Leadership

Is there a question there?


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

0 Kudos
mario_981
Enthusiast
Enthusiast

yes , I have a question - how can I get the permissions of each datacenter under each folder of type datacenter.

Also I have to export it to csv. I am struck with above snippet.

0 Kudos
LucD
Leadership
Leadership

Did you try like this?

Get-Folder -Type Datacenter |

   Get-Datacenter |

   Get-VIPermission |

   Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

0 Kudos
mario_981
Enthusiast
Enthusiast

No I didnt try this way, let me give it a try.

0 Kudos
mario_981
Enthusiast
Enthusiast

The snippet gave output which had entity names like screenshot attached.

I wanted the foldernames and datacenter names so I tried something like this

foreach($folder in Get-Folder -Type Datacenter)

  {  

        foreach ($dc in Get-Datacenter -Location $folder)

            {

                    Get-VIPermission -Entity $folder |

                    Select @{N='Folder'; E={$folder.Name}},

                           @{N='Datacenter'; E={$dc.Name}},

                           Role,

                           Principal,

                           Propagate,

                           IsGroup                     

            }

    }

  } | Export-Csv C:\output\DatacenterPermissions_$CurrentDate.csv -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership

You didn't say which properties you wanted in the CSV.
And I would be very much amazed if that script actually works


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

0 Kudos
mario_981
Enthusiast
Enthusiast

To do this like earlier

Get-Folder -Type Datacenter |

   Get-VIPermission |

   Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

could you tell me how to do it , I need to select the folder name property and find permissions against it.

0 Kudos
LucD
Leadership
Leadership

You could try like this

Get-Folder -Type Datacenter -PipelineVariable folder |

Get-Datacenter -PipelineVariable dc |

Get-VIPermission |

Select @{N = 'Folder'; E = {$folder.Name}},

   @{N = 'Datacenter'; E = {$dc.Name}},

  Role,

  Principal,

  Propagate,

  IsGroup |

Export-Csv C:\output\DatacenterPermissions_$CurrentDate.csv -NoTypeInformation -UseCulture


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

0 Kudos