@Andreas Baumgarten
Thanks for your suggestion.
The total number of users in the AD will be approximately 1300.
There the approximately 15 locations on our domain and 20 Domain Controllers.
Our OU Structure is as given below.
a) Each location has a separate OU.
b) Under each location there are Computers OU, Groups OU & Users OU.
I have created two test users as follows.
Location OU > LocalUsers OU > GPO_Test OU > Test.User1 & Test.User2
I have only this two test users in the list on the DisableUsers.csv file and using the script mentioned earlier to disable this two users.
It is working fine except it takes long time to disable the users.
Do you think the query will take faster effect if I limit my search by adding the line as you have suggested ?
( Get-ADUser -Identity $($user.name) -SearchBase "OU=UserAccounts,DC=YOURDOMAIN,DC=LOCAL" | Disable-ADAccount )
In that case the new script will look like as shown below.
Import-Module ActiveDirectory
$userlist=Import-CSV C:\ADUSERS\DisableUsers.csv
ForEach ($user in $userlist)
{
Get-ADUser -Identity $($user.name) -SearchBase "OU=GPO_Test,OU=LocalUsers,OU=Location,DC=OurDomain,DC=local” | Disable-ADAccount
write-host "user $($user.name) has been disabled"
}
After running the script I am getting the following error.
Get-ADUser : Parameter set cannot be resolved using the specified named parameters.
At line:12 char:6
- Get-ADUser -Identity $($user.name) -SearchBase "OU=GPO_Test,OU=L ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
- FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.ActiveDirectory.Management.Commands.GetADUser
My line 12 is given below.
Get-ADUser -Identity $($user.name) -SearchBase "OU=GPO_Test,OU=LocalUsers,OU=Location,DC=OurDomain,DC=local” | Disable-ADAccount
Kindly suggest if I am missing anything else.
Thanks
Pankaj