Created
November 13, 2017 02:38
-
-
Save ellieayla/798ef2703c81654c88da5db182bae10c to your computer and use it in GitHub Desktop.
Create a vSphere Resource Pool for every user in an Active Directory group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For every user with membership in an Active Directory group, | |
# ... create a vSphere Resource Pool named after the user | |
# ... give that user permissions to the resource pool and its childen. | |
Connect-VIServer vcsa-01a.corp.local | |
$poweruser = Get-VIRole "VirtualMachinePowerUser" | |
$adusers = Get-ADGroupMember "VMPowerUsers" | |
$newuserpool = Get-ResourcePool "NewUsers" | |
foreach ($aduser in $adusers) { | |
$username = $aduser.name | |
$viaccount = Get-VIAccount -domain "CORP" $username -ErrorAction Stop | |
try { | |
$userpool = $newuserpool | Get-ResourcePool -Name $username -ErrorAction Stop | |
} Catch { | |
$userpool = $newuserpool | New-ResourcePool -Name $username -ErrorAction Stop | |
} | |
$newpermission = New-VIPermission -Principal $viaccount -Role $poweruser -Entity $userpool | |
$extrapowerusers = $userpool | Get-VIPermission | Where Role -eq $poweruser | Where Principal -ne $viaccount | |
if ($extrapowerusers) { | |
Write-Host "Resource pool $userpool has extra user permissions: ", $extrapowerusers | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment