Find a related account in AD
hi,
i have written below script user based on conditions, move user different ou, remove multiple groups user. not sure how write code below requirement.
the requirement , once user, need find associated admin account if exist (for eg., if found user (samaccountname - abc001) below script, related admin account "admabc001", means "adm" prefix user's account) , same activity move ou , remove groups.
logprogress seperate function.
please me write code requirement.
$groups= get-content "c:\scripts\moveadgroups\groups.txt"
$activedirectoryserver = "test.ia"
$office = "test"
$date = (get-date).adddays(-2)
try {
$users = get-aduser -filter{(office -eq $office) -and (whenchanged -ge $date)} -properties samaccountname -erroraction stop -server $activedirectoryserver
}
catch {
logprogress -logtype "error" -logline "failed load the list of users. error was: $($error[0])."
}
logprogress -logtype "information" -logline "the current user $users"
foreach($user in $users){
try {
move-adobject -identity $user -targetpath $targetpath
}
catch {
logprogress -logtype "error" -logline "failed move user. error was: $($error[0])."
}
logprogress -logtype "information" -logline "user has been moved $targetpath"
$groups | foreach {
try{
remove-adgroupmember -identity $_ -members $user -confirm:$false
}
catch {
logprogress -logtype "error" -logline "user has been failed remove user. error was: $($error[0])."
}
}
hi mike,
thanks reply,
$user= "abc001" not "samaccountname - abc001".
okay, that's easier then:
$user = 'abc001' $adminaccount = "adm$($user)" $adminaccount
Windows Server > Windows PowerShell
Comments
Post a Comment