remove computer from group in flow designer

Cherly
Tera Contributor

i need to remove a computer from AD via flow designer. I need help creating and action and I try creating a similar action to the remove user but got a powershell error

action created was 

import-module "$executingScriptDirectory\ADSpoke\ActiveDirectoryMain"

if (test-path env:\SNC_groupname) {
$groupname = $env:SNC_groupname;
$username = $env:SNC_username;
};
$groupname = $groupname -replace "%27","'";
$username = $username -replace "%27","'";
removeADComputerFromGroup -domainController $computer -username $username -groupname $groupname -useCred $useCred -credential $cred

 

from active directorymain

###################################
# Remove Computer from Group
# Custom Function
###################################>
function removeComputerFromGroup {
param([string]$domainController, [string]$username, [string]$groupname, [boolean]$useCred, [System.Management.Automation.PSCredential]$credential)

SNCLog-ParameterInfo @("Running removeADUserAccountFromGroup", $domainController, $username, $groupname)

$userObject = getADObject -domainController $domainController -type "Computer" -objectName $username -useCred $useCred -credential $credential
$groupObject = getADObject -domainController $domainController -type "Group" -objectName $groupname -useCred $useCred -credential $credential

$groupObject.remove("LDAP://"+$userObject.distinguishedName);
if (-not $?) {
SNCLog-DebugInfo "`tFailed to remove $username computer from $groupname group, $error"
}
}

7 REPLIES 7

Aoife
Tera Guru

Need a bit more information.

1. Why did you not use the ServiceNow pre-built Flow actions for MSAD?

2. What specific error did you receive?

 

Aoife

Cherly
Tera Contributor

 remove computer is not an action on the prebuilt flow actions

 

Sure it is, it is called Delete Computer.

See below:

find_real_file.png

Cherly
Tera Contributor

i need to remove it from an AD group not from AD.