Quantcast
Viewing all articles
Browse latest Browse all 3135

Backup vCenter Server Roles details

The below script will export the details of existing vCenter Server Roles details.

 

Copy the below piece of code and paste it onto a text file and save it as .PS1 file. Then run it in PowerCLI:

#requires -Version 3   
[CmdletBinding(SupportsShouldProcess)]  
  Param(  
   [Parameter(Mandatory=$true, Position=1,  
    ValueFromPipeline=$true)]  
   [AllowNull()]  
   [alias("LiteralPath")]  
   [string]$Path = "c:\temp"   
  ) #Param  
Begin { 
   $DefaultRoles = "NoAccess", "Anonymous", "View", "ReadOnly", "Admin", "VirtualMachinePowerUser", "VirtualMachineUser", "ResourcePoolAdministrator", "VMwareConsolidatedBackupUser", "DatastoreConsumer", "NetworkConsumer" 
   $DefaultRolescount = $defaultRoles.Count 
   $CustomRoles = @() 
} #Begin 
  
Process { 
   $AllVIRoles = Get-VIRole 
  
   0..($DefaultRolescount) | ForEach-Object { 
     if ($(Get-Variable "role$_" -ErrorAction SilentlyContinue)) { 
       Remove-Variable "role$_" -Force -Confirm:$false 
     } #if ($(Get-Variable "role$_" -ErrorAction SilentlyContinue)) 
   } #0..($DefaultRolescount) | Foreach-Object 
  
   0..$DefaultRolescount | ForEach-Object { 
     $DefaultRolesnumber = $DefaultRoles[$_] 
     if ($_ -eq 0) { 
       New-Variable "role$_" -Option AllScope -Value ($AllVIRoles | Where-Object {$_.Name -ne $DefaultRolesnumber}) 
     } #if ($_ -eq 0) 
     else { 
       $vartxt = $_ - 1 
       $lastrole = 'role'+"$vartxt" 
       #Get-Variable $lastrole 
       New-Variable "role$_" -Option AllScope -Value (Get-Variable "$lastrole" | select -ExpandProperty value | Where-Object {$_.Name -ne $DefaultRolesnumber}) 
     } #else ($_ -eq 0) 
   } #0..$DefaultRolescount | ForEach-Object 
   $filteredRoles = Get-Variable "role$($DefaultRolescount-1)" | select -ExpandProperty value 
} #Process 
End { 
   $filteredRoles | ForEach-Object { 
     $completePath = Join-Path -Path $Path -ChildPath "$_.role" 
     Write-Host "Exporting Role `"$($_.Name)`" to `"$completePath`"" -ForegroundColor Yellow 
     $_ | Get-VIPrivilege | select-object -ExpandProperty Id | Out-File -FilePath $completePath 
   } #$filteredRoles | ForEach-Object 
} #End   #To Export Permissions:Get-VIPermission | export-csv c:\temp\rights.csv

 

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 3135

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>