Termed Employee script
i trying learn powershell. making script
1. reads file (currently txt) has usernames , read each line username variable.
2. finds user in ad, moves account ou, disables account, removes hmdrive , hmdir
3. checks exists on users directory on share.
any help\guidance great.
$username = get-content -path c:\temp\test.txt
foreach ($username in $user) {
get-qaduser -samaccountname $username |
disable-qaduser |
set-qaduser -homedirectory $null |
set-qaduser -homedrive $null |
set-qaduser -logonscript $null | fl name,samaccountname,homedrive,homedirectory,emailaddresspolicyenabled}
move-qadobject $users -newparentcontainer "ou=termed employees,ou=ou_users,dc=domain,dc=domain,dc=com"
if (test-path -path \\evergreen\ehc\users\$username )
{
#move-item \\path\path\users\$username \\path\path\users\0lduserdirectories\$username
'it exist'
}
else
{
'does not exist'
}
jason
try this. each statement on separate line, not piped.
$username = get-content -path c:\temp\test.txt foreach ($user in $username) { $curruser = get-qaduser -samaccountname $user disable-qaduser $curruser set-qaduser $curruser -homedirectory $null set-qaduser $curruser -homedrive $null set-qaduser $curruser -logonscript $null move-qadobject $curruser -newparentcontainer "ou=termed employees,ou=ou_users,dc=domain,dc=domain,dc=com" }
grant ward, a.k.a. bigteddy
Windows Server > Windows PowerShell
Comments
Post a Comment