Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save omniproc/7b6309c6238abfae8bb0ac8330324941 to your computer and use it in GitHub Desktop.
Save omniproc/7b6309c6238abfae8bb0ac8330324941 to your computer and use it in GitHub Desktop.
#Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
$vcenterServer = YOUR_VCENTER_SERVER_FQDN
$cluster = YOUR_VCENTER_CLUSTER
$esxiUser = "root"
$esxiPass = "YourMama"
$newUserName = "NameOfTheUserYouWantToAdd"
$newUserDomain = "DomainNameOfTheUserYouWantToAdd"
Try
{
Connect-VIServer -Server $vcenterServer
$esxlist = Get-Cluster $cluster | Get-VMHost
foreach($esx in $esxlist)
{
Connect-VIServer -Server $esx.Name -User $esxiUser -Password $esxiPass
New-VIPermission `
-Entity (Get-Folder -NoRecursion -Server $esx.Name) `
-Principal (Get-VIAccount -Domain $newUserDomain -User $newUserName -Server $esx.Name) `
-Propagate $true `
-Role (Get-VIRole -Name ReadOnly -Server $esx.Name)
Disconnect-VIServer -Confirm:$false -Server $esx.Name
}
Disconnect-VIServer -Confirm:$false *
}
Catch
{
Disconnect-VIServer -Confirm:$false *
Write-Host "Error occured while processing. Exit."
}
#Get-VIPermission -Principal (Get-VIAccount -Domain $newUserDomain -User $newUserName ) | select-object *
#Remove-VIPermission -Permission (Get-VIPermission -Principal (Get-VIAccount -Domain $newUserDomain -User $newUserName ))
@omniproc
Copy link
Author

omniproc commented Apr 6, 2016

Adds a Active Directory user as local user to all ESXi hosts within a vCenter cluster and assigns it read-only permissions. Usefull if Active Directory based authentication has been enabled within a cluster and local users need to be added, e.g. for monitoring services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment