Hello LucD,
I'm new to this and I'm stuck with vCenter Importing roles and permissions there is an error.. I will share the codes whatever I have it with me - need some help on this. We have created two output types - csv for human readable and XML for importing on vCenter. Kindly help on importing script part. I did try your import script but there is some error (posted in the end of the this thread).
This is the exporting of role and permission script:
#vCenter Role & Permission export#
Write-Host "`tExporting Permissions and Roles for vCenter.."
$vCenterHost = Read-Host "Enter vCenter Name:"
try {
#Establishing connection to vCenter
Connect-VIServer -Server $vCenterHost
#Permissions
$Permission = Get-VIPermission | Select-Object @{N='vCenter';E={$_.Uid.Split('@:')[1]}},
Principal,Role,propagate,
@{n='Entity';E={$_.Entity.Name}},
@{N='Entity Type';E={$_.EntityId.Split('-')[0]}}
#Export to CSV
$Permission | Export-Csv -Path "C:\Temp\$vCenterHost-Permission.csv"
#Export to XML
$PermissionXML = Get-VIPermission
$PermissionXML | Export-Clixml -Path "C:\Temp\$vCenterHost-Permission.xml"
#Roles
$Role = Get-VIRole | Select-Object @{N='vCenter';E={$_.Uid.Split('@:')[1]}},
Name,
@{N='PrivilegeList';E={[string]::Join([char]10,$_.PrivilegeList)}}
#Export to CSV
$Role | Export-Csv -Path "C:\Temp\$vCenterHost-Roles.csv"
#Export to XML
$RoleXML = Get-VIRole
$RoleXML | Export-Clixml -Path "C:\Temp\$vCenterHost-Roles.xml"
Write-Verbose "`tRole & Permission Data Exported Successfully from $vCenterHost" -Verbose
Write-Verbose "Disconnecting from $vCenterHost" -Verbose
Disconnect-VIServer -Server
}
catch {
Write-Verbose "`tError Encountered! Error:$_" -Verbose
$ErrorObject = New-Object -TypeName PSObject -Property @{
vCenterName = $vCenterHost
Error = $_
}
}
Import script error output:
New-VIPermission : Cannot process argument transformation on parameter 'Principal'. This parameter no longer accepts
an array. As an alternative you may pass multiple values by pipeline (if supported by the parameter).
At D:\Script\Import of role and permission of vcenter (1).ps1:12 char:18
+ New-Vipermission $Permission
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-VIPermission], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Permis
sionManagement.NewVIPermission
Import Script which I'm referring to:
Import-excel -Path $reportName -WorksheetName Permissions -PipelineVariable row |
Foreach-Object -process {
$Permission = @{
Entity = Get-Inventory -Name $row.Entity
Role = Get-VIRole -name $row.Role
#Principal = $row.Principal
Propagate = $row.Propagate
Confirm = $false }
New-VIPermission $Permission
}