Hello,
Please help. The guys on this site have been awesome and I really appreciate all of your help, but I have 1 more issue. My script works almost perfectly, but I can’t get one thing to work and that’s the Move-ADObject to work. The script does everything I need it to, but Move the ADUser to the Disabled Users OU. Here’s my script.
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.SamAccountName -Confirm:$false
Add-ADGroupMember -Identity "DisabledUsers" -Members $User.SamAccountName
Disable-ADAccount -Identity $($User.SamAccountname)
}
else
{
Remove-ADPrincipalGroupMembership -Identity $($User.SamAccountname) -MemberOf $ADgroups.SamAccountName -Confirm:$false
Add-ADGroupMember -Identity "DisabledUsers" -Members $User.SamAccountName
Get-ADUser -Identity $User.SamAccountName | Move-ADObject -targetpath $TargetOU
Disable-ADAccount -Identity $($User.SamAccountname)
}
}
This is the error I’m getting:
The 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 : GGPDC01