I wrote this because I want to find all my samAccoutname in my csv to disable them, then move them.
$CleanupUsers = Import-Csv -Path .\CleaupUsers.csv
ForEach ($user in $CleanupUsers) {
Get-ADUser $($user.samAccountName) |
Disable-ADAccount -Identity $($user.samAccountName) |
Move-ADObject -Identity $($user.samAccountName) -TargetPath "OU=DisabledUsers,DC=corp,DC=com"
}
..it's not working as I expect. Help says -Identity for Disable-ADAccount and Move-ADObject accepts pipeline By Value but not sure how to generate that.
Some progress. I just piped Get-ADuser into disable-ADAccount:
$CleanupUsers = Import-Csv -Path .\CleaupUsers.csv
ForEach ($user in $CleanupUsers) {
Get-ADUser $($user.samAccountName) |
Disable-ADAccount |
#Move-ADObject -Identity $($user.samAccountName) -TargetPath "OU=DisabledUsers,DC=corp,DC=com"
}
...have to figure out Move-ADObject next. I somehow have to get it to see a DN foreach object, right?