diabale and move account in AD via powershell

Hi

I would like to dis able a user account in ad and move them to a different OU.  the thing is I would like to do it via there employee ID number.  this way I can be 100% the I have the right person.

does anyone have a script like that or know of one that I can take a look at?

thanks

SEHC
LVL 4
SEHCAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
If you could have the SAM account name it can be done. No idea if EmployeeID is related with sam account name or login name how it is setup in AD.
Can you let us know this please.
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
$samAccountName = "AbdulRaheman"
Disable-ADAccount -Identity $samAccountName 

Get-ADUser -Identity $samAccountName | Move-ADObject -TargetPath 'OU=Destination,OU=CEApps,DC=domain,Dc=com'

Open in new window

0
Will SzymkowskiSenior Solution ArchitectCommented:
Try the following code below...
Import-module activedirectory
$User = "username"
$OU = "ou=domain users,dc=example,dc=com"
Get-ADUser -Filter { EmployeeID -eq $User.EmployeeID } -Properties EmployeeID | Disable-ADAccount | Move-ADObject -Identity $User.distinguishedname -TargetPath $OU

Open in new window


Will.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

SEHCAuthor Commented:
Hi Will

can you send me the columns for the CSV?
0
Will SzymkowskiSenior Solution ArchitectCommented:
You want to do this for multiple users that are in a csv file?

Will.
0
SEHCAuthor Commented:
yes please I would like to do this for multiple users
0
Will SzymkowskiSenior Solution ArchitectCommented:
I will modify the script and post back shortly.

Will.
0
SEHCAuthor Commented:
thanks Will
0
Will SzymkowskiSenior Solution ArchitectCommented:
What info does your CSV file currently have?

Do you only have the EmployeeID?

Will.
0
Will SzymkowskiSenior Solution ArchitectCommented:
I have modified the script based on you only having the EmployeeID info. If you have additional info in your CSV please let me know and i will add the changes.

Import-module activedirectory
$OU = "ou=domain users,dc=example,dc=com"
$UserList = Import-Csv "c:\filename.csv"
ForEach ($User in $UserList) {
$User.EmployeeID
Get-ADUser -Filter { EmployeeID -eq $User.EmployeeID } -Properties EmployeeID | Disable-ADAccount | 
Move-ADObject -Identity $User.distinguishedname -TargetPath $OU
}

Open in new window


Will.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SEHCAuthor Commented:
there is no files at the moment.
0
Will SzymkowskiSenior Solution ArchitectCommented:
So, based on the script above that i have modified you need to construct your CSV like below...
EmployeeID
012331
123150
995844
etc

Or whatever values you have listed in the EmployeeID attribute need to be under the heading EmployeeID in the CSV file.

Will.
0
SEHCAuthor Commented:
HI


I am getting the following error

Move-ADObject : Cannot validate argument on parameter 'Identity'. The argument
is null. Supply a non-null argument and try the command again.
At C:\Scripts\AD Powershell scripts\Disable account employee ID\adempdis.ps1:6
char:24
+ Move-ADObject -Identity <<<<  $User.distinguishedname -TargetPath $OU
    + CategoryInfo          : InvalidData: (:) [Move-ADObject], ParameterBindi
   ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
   eDirectory.Management.Commands.MoveADObject
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.