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?
 
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
 
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.