Automation

 View Only
  • 1.  export roles from one vcenter and import to another

    Posted Nov 15, 2016 05:05 PM

    I got 6 vcrnters that I need to create the same role

    how do I export the rtole from one vcenter and import into another?



  • 2.  RE: export roles from one vcenter and import to another



  • 3.  RE: export roles from one vcenter and import to another

    Posted Dec 12, 2016 02:14 PM

    Hi tdubb123

    Did you have a chance to read the blog post I referenced in my previous post? Do you have any additional doubt? If not, remember to mark answers as helpful or correct.



  • 4.  RE: export roles from one vcenter and import to another

    Posted Nov 11, 2022 01:37 AM

    was this ever solved?



  • 5.  RE: export roles from one vcenter and import to another

    Posted Nov 11, 2022 07:36 AM

    Export

    Get-VIRole |
    Select @{N='vCenter';E={$_.Uid.Split('@:')[1]}},
      Name,
      @{N='PrivilegeList';E={[string]::Join([char]10,$_.PrivilegeList)}} |
    Export-Csv -Path .\roles.csv -NoTypeInformation -UseCulture


    Import

    Import-Csv -Path .\roles.csv -PipelineVariable row |
    ForEach-Object -Process {
      $Role = @{
        Name = $row.Name
        Privilege = $row.PrivilegeList.Split("`n") | ForEach-Object { Get-VIPrivilege -Id $_ }
        Server = $row.vCenter
        Confirm = $false
        WhatIf = $true
      }
      New-VIRole 
    }


    Note that you will have to exclude the system-defined Roles.
    They are created automatically, and a user can not create those



  • 6.  RE: export roles from one vcenter and import to another

    Posted Nov 10, 2023 04:13 PM

    I know this is an ancient thread but I wanted to say thank you to Luc. This still works in 8.0U2. I have been meaning to find a way to export and import our custom roles for ages and finally got around to it. 

     



  • 7.  RE: export roles from one vcenter and import to another

    Broadcom Employee
    Posted Nov 01, 2024 01:47 PM

    When I run the import section I am getting asked to supply a value for the following parameters: Name:. $Role returns my first role export in the CSV. any thoughts? 




  • 8.  RE: export roles from one vcenter and import to another

    Posted Nov 01, 2024 01:49 PM

    Looks like part of the code got dropped in one of the migrations.
    Try like this

    Import-Csv -Path .\roles.csv -PipelineVariable row |
    ForEach-Object -Process {
      $Role = @{
        Name = $row.Name
        Privilege = $row.PrivilegeList.Split("`n") | ForEach-Object { Get-VIPrivilege -Id $_ }
        Server = $row.vCenter
        Confirm = $false
        WhatIf = $true
      }
      New-VIRole @Role
    }


    ------------------------------


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


    ------------------------------



  • 9.  RE: export roles from one vcenter and import to another

    Broadcom Employee
    Posted Nov 01, 2024 02:20 PM

    Thanks! That was it.