Author Posts

July 27, 2018 at 9:24 pm

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" 
}'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?

July 27, 2018 at 10:27 pm

If you like to pipe something to a cmdlet you have to have something to pipe to it. 😉 So you should make sure the cmdlet you're using to feed the next cmdlet produces any output. Read the help for Disable-ADAccount please. ... and then add -PassThru to it.
You should read the help for the cmdlets you're about to use COMPLETELY including the examples.

July 27, 2018 at 10:34 pm

ok I see now "By default (i.e. if -PassThru is not specified), this cmdlet does not generate any output."

thank you Olaf