So I have a bit of an oddf one.
when I run the following command direct it runs and achieves the desired outcome ( removes all computers from a specific AD security group)
Get-ADGroupMember -Identity "Checkpoint_deployment_endpoint_test_phase" | Remove-ADPrincipalGroupMembership -MemberOf "Checkpoint_deployment_endpoint_test_phase" -Confirm:$false
Howver when I run the same command as part of a script ( the script empties out the Ad group then repopulates it based upon computer name)
It Generates an error
H:\scripts\checkpoint deployment phase script> .\checkpoint_deployment_phase_script Remove-ADPrincipalGroupMembership : Object reference not set to an instance of an object. At H:\scripts\checkpoint deployment phase script\checkpoint_deployment_phase_script.ps1:7 char:75 + ... st_phase" | Remove-ADPrincipalGroupMembership -MemberOf "Checkpoint_d ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Remove-ADPrincipalGroupMembership], NullReferenceException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.RemoveADPrincipalGroupMembership
Any suggestion as to the cause of the difference in behaviour?