PLs Help need Bulk Disable Account but I need to compile Description field

Hi Guys,
I’m in Active direcotory Win server and I need to do what i ask belove. I’m no soo good with script I find this code to disable and move account

“Get-Content D:\script\moveruser.csv | Get-ADUser | Move-ADObject -TargetPath “OU=test2,DC=contoso,dc=org” -PassThru | Disable-ADAccount”

but now the must difficult things for me is that:

I need to do for a list of account (have .cvs list): Copy what in the Object Tab (Canonical field), paste in the Description field but like the Example:
In Description I have: “y.y”. I need to obtain: y.y + “origin” + paste what was in Object tab filed + “Disalbed xx/xx/2018”.

Pls help txxx

sorry for my english :wink:

So lets break down that command you found.

Get-Content D:\script\moveruser.csv |

Get the users from your csv, although since you’re coming from a csv an import-csv would parse this better for you. If you had a .txt file then Get-Content would be the route you wanted

Get-ADUser |

Retrieve the ADUser object for the DN you imported

Move-ADObject -TargetPath “OU=test2,DC=contoso,dc=org” -PassThru |

Move the object to the new OU, including the passthru parameter so you get some output to pass onto the disable command.

Disable-ADAccount

Disable that account

 

You probably want to write this out into more of a script than a one liner. This will give you greater flexibility in what to do with it. I’m writing this on the fly with no testing and not 100% what you mean by your “y.y” statements, but it will hopefully get you moving down the right path.

$Users = get-content D:\script\moveruser.txt

ForEach ($user in $users)

{

$userobj = get-aduser $user

$description = "$userobj.description Disabled on "+(get-date).ToShortDateString()

set-aduser $userobj -replace {description="$description"}

disable-adaccount $userobj

Move-ADObject $userobj -TargetPath "OU=test2,DC=contoso,dc=org

}

You could also use the import-csv rather than get-content of your csv file. But then you’d need to know what your column header is named to reference the property. But since I don’t know that I’m just assuming your csv is a single column of DNs that can be moved to a txt file.

duplicate

duplicate, sorry