How to add AD groups to Computer Account via Flow Designer

Brian Dean
Tera Expert

Hello Developers, 

 

Does anyone know what script can be used in Flow Designer Actions to add the AD groups to the computer account? 

I could not find any OOTB action for "Add group to Computer Account" so I tweaked the script "Add User to Groups" on the Mid Server Script file to the following below. Does that script looks OK? 

 

import-module "$executingScriptDirectory\ADSpoke\ActiveDirectoryMain"

 

 

if (test-path env:\SNC_computername) {

  $computername = $env:SNC_computername;

  $ou = $env:SNC_OU;

};

                $rootEntry = getDirectoryEntryObject -path "LDAP://$computer" -useCred $useCred -credential $cred

                $search = New-Object System.DirectoryServices.DirectorySearcher $rootEntry;

                $search.Filter = "(&(objectClass=Computer)(CN=$computername))";

                $result = $search.FindOne();

                if ($result -eq $null) {

                                SNCLog-DebugInfo "`tUnable to find the Computer"

                                throw New-Object System.ArgumentException($search.Filter + " could not be found");

                }

                $object = $result.GetDirectoryEntry();

 

        $ouPath ="LDAP://$computer"+"/"+ $ou;

                $newOU = getDirectoryEntryObject -path $ouPath -useCred $useCred -credential $cred

        if ($newOU -eq $null) {

                                SNCLog-DebugInfo "`tUnable to find the OU"

                                throw New-Object System.ArgumentException( "OU could not be found");

                }

$object.MoveTo($newOU)

0 REPLIES 0