0

I'm using a script that creates groups in Active Directory, and links them to my vCenter server using New-VIPermission. The trick is that it doesn't find the groups created unless I restart the script (and so, I guess, the connexion).

$My_Group = New-QADGroup -Name $My_AD_GroupName -SamAccountName $My_AD_GroupName -ParentContainer $My_OU -Connection $My_adConnection 
New-VIPermission -Entity $param_objects -Principal "Domain\$My_AD_GroupName" -Role ($My_Role.Name) -Propagate:($My_Role.Value) | Out-Null

This script will create the group in my AD, but when coming to linking it to a new permission in my vCenter, it will return New-VIPermission Could not find VIAccount with name 'Domain\MY_GROUP_NAME'.

When restarting the script, it will pass over the group creation directly to the New-VIPermission, and correctly link it to the vCenter object.

I've tried, to add a Wait command, and a 5 seconds sleep, but wont change a thing...

How can I manage to reload the list of availaible groups without restarting the vCenter connexion ?

Thanks in advance !

1 Answer 1

1

Got an answer from the vmware forums : cache refreshing was the issue. I added a while to test if the group could be resolved in vCenter to solve the issue :

while (!(Get-VIAccount -Group -Name "DOMAIN\$My_AD_GroupName")){Start-sleep -s 1}

Just after the AD group creation and... well it's slow, but it works :)

1
  • Note that you have to use the NETBIOS/short domain name (this stumped me). Your answer helped me figure that out.
    – KERR
    Nov 30, 2017 at 4:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .