-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImport-vCenter-Permissions2.ps1
44 lines (43 loc) · 1.5 KB
/
Import-vCenter-Permissions2.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<#
.Synopsis
Imports roles into vsphere roles..
.Description
This script imports roles into vspheres from .role file/
.Example
Import-vSphereRoles -Path c:\temp
Import Roles to the folder.
.Notes
NAME: Import-vSphereRoles
AUTHOR: Kunal Udapi
LASTEDIT: 15th February 2016
KEYWORDS: Import Roles
.Link
#Check Online version: http://kunaludapi.blogspot.com
#Requires -Version 3.0
#>
#requires -Version 3
[CmdletBinding(SupportsShouldProcess)]
Param(
[Parameter(Mandatory=$true, Position=1,
ValueFromPipeline=$true)]
[AllowNull()]
[alias("LiteralPath")]
[string]$Path = "."
) #Param
Begin {
$roleFiles = Get-ChildItem -Path $Path -Filter *.role
}
Process {
foreach ($role in $roleFiles) {
$VIRoleName = $role.BaseName
$RolesContent = Get-Content -Path $role.FullName
New-Virole -Name $VIRoleName | Out-Null
Write-Host "Created Role `"$VIRoleName`"" -BackgroundColor DarkGreen
foreach ($Privilege in $RolesContent) {
if (-not($privilege -eq $null -or $privilage -eq "")) {
Write-Host "Setting Permissions `"$Privilege`" on Role `"$VIRoleName`"" -ForegroundColor Yellow
Set-VIRole -Role $VIRoleName -AddPrivilege (Get-VIPrivilege -ID $privilege) | Out-Null
} #if (-not($privilege -eq $null -or $privilage -eq ""))
} #foreach ($Privilege in $RolesContent)
} #foreach ($role in $roleFiles)
}