VMware Cloud Community
pakempf
Contributor
Contributor
Jump to solution

Refresh VIAccounts list with PowerCli to select a newly created group

Hello everyone,

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/refresh the list of availaible groups without restarting the vCenter connexion ?

Thanks in advance !

Reply
0 Kudos
1 Solution

Accepted Solutions
pakempf
Contributor
Contributor
Jump to solution

Well, I added the following :

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

And it works. Slow but it works Smiley Happy

Thanks, LucD ! :smileygrin:

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

There are at least 2 factors that could potentially impact this: AD replication and the cache refresh on the vCenter.

You could test if the new group can be resolved on the vCenter.

If you do that in a While-loop, you can wait till ready, and then execute the New-VIPermission cmdlet


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

pakempf
Contributor
Contributor
Jump to solution

Well, I added the following :

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

And it works. Slow but it works Smiley Happy

Thanks, LucD ! :smileygrin:

Reply
0 Kudos