Hello, Please help. I’m new to Power shell and I’m having a hard time. I have been working on this same script for weeks. I thought I had it working, but now it can’t bind parameter MemberOf.
Import-Module ActiveDirectory
$users= Import-Csv -Path “C:\Output\DisableADUsers91718C.csv”
$DisabledDate = Get-Date
$LeaveDate = Get-Date -Format “dddd dd MMMM yyyy”
$DisabledBy = Get-ADUser “$env:username” -properties Mail
$DisabledByEmail = $DisabledBy.Mail
$LegalHoldUser = Get-ADuser -Filter * -SearchBase ‘ou=LegalHold,dc=xxx,dc=com’ -Properties * | Select-object -Expand SamAccountName
$TargetOU = “ou=Disabled Users,dc=xxx,dc=com”
foreach ($user in $users)
{
$SamAccountName = $User.SamAccountName
Set-ADUser $User.SamAccountName -Description "Disabled by $($DisabledBy.name) on $DisabledDate per Ticket INC0065513"
$ADgroups = Get-ADPrincipalGroupMembership -Identity $User.SamAccountName | where { ($_.Name -ne 'Domain Users') -and ($_.Name -ne 'DisabledUsers') }
If ($LegalHoldUser -contains $User.SamAccountname)
{
Remove-ADPrincipalGroupMembership -Identity $($User.SamAccountname) -MemberOf $ADgroups -Confirm:$false
Add-ADGroupMember -Identity "DisabledUsers" -Members $User.SamAccountName
Disable-ADAccount -Identity $($User.SamAccountname)
}
else
{
Remove-ADPrincipalGroupMembership -Identity $($User.SamAccountname) -MemberOf $ADgroups -Confirm:$false
Add-ADGroupMember -Identity "DisabledUsers" -Members $User.SamAccountName
Get-AdUser $SamAccountName | Move-ADObject -targetpath $TargetOU
Disable-ADAccount -Identity $($User.SamAccountname)
}
}
Here’s the error message:
Cannot bind parameter ‘MemberOf’. Cannot convert value “CN=Okta Concur,OU=Okta Security Groups,OU=Domain Groups,DC=xxx,DC=com” to type “Microsoft.ActiveDirectory.Management.ADGroup”. Error: “Cannot convert the “CN=Okta Concur,OU=Okta
Security Groups,OU=Domain Groups,DC=xxx,DC=com” value of type “Deserialized.Microsoft.ActiveDirectory.Management.ADGroup” to type “Microsoft.ActiveDirectory.Management.ADGroup”.”
+ CategoryInfo : InvalidArgument: ( [Remove-ADPrincipalGroupMembership], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.RemoveADPrincipalGroupMembership
+ PSComputerName : GGPDC01Cannot bind parameter ‘MemberOf’. Cannot convert value “CN=REPORTS-SALES,OU=Applications,OU=Domain Groups,DC=mecca,DC=com” to type “Microsoft.ActiveDirectory.Management.ADGroup”. Error: “Cannot convert the
“CN=REPORTS-SALES,OU=Applications,OU=Domain Groups,DC=xxx,DC=com” value of type “Deserialized.Microsoft.ActiveDirectory.Management.ADGroup” to type “Microsoft.ActiveDirectory.Management.ADGroup”.”
+ CategoryInfo : InvalidArgument: ( [Remove-ADPrincipalGroupMembership], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.RemoveADPrincipalGroupMembership
+ PSComputerName : GGPDC01The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
+ CategoryInfo : InvalidArgument: (CN=Adam Abston,…DC=xxx,DC=com:PSObject) [Move-ADObject], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.ActiveDirectory.Management.Commands.MoveADObject
+ PSComputerName : GGPDC01Cannot bind parameter ‘MemberOf’. Cannot convert value “CN=Okta Concur,OU=Okta Security Groups,OU=Domain Groups,DC=xxx,DC=com” to type “Microsoft.ActiveDirectory.Management.ADGroup”. Error: “Cannot convert the “CN=Okta Concur,OU=Okta
Security Groups,OU=Domain Groups,DC=xxx,DC=com” value of type “Deserialized.Microsoft.ActiveDirectory.Management.ADGroup” to type “Microsoft.ActiveDirectory.Management.ADGroup”.”
+ CategoryInfo : InvalidArgument: ( [Remove-ADPrincipalGroupMembership], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.RemoveADPrincipalGroupMembership
+ PSComputerName : GGPDC01The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
+ CategoryInfo : InvalidArgument: (CN=Adam Wright,…DC=xxx,DC=com:PSObject) [Move-ADObject], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.ActiveDirectory.Management.Commands.MoveADObject
+ PSComputerName : GGPDC01