Solved

Disable multiple AD accounts with powershell

Posted on 2015-01-15
2
110 Views
Last Modified: 2015-01-29
hi EE

Can someone please help me modify this so the script also disables the accounts .
The script should the disable the accounts and add the note.

GC Users.txt | % {
$note = (Get-ADUser $_ -Properties info).info
$info = "Disabled- 01/15/2014-Last Logon Greater then 90 days " 
If ($note -ne $null){
Set-ADUser $_ -replace @{info="$note`r`n$info"}
}Else{
Set-ADUser $_ -replace @{info=$info}
}
}
0
Comment
Question by:MilesLogan
2 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40551577
I am assuming you want to disable and simply append if a note already exists:

Disable Ad Account should do that for you

GC Users.txt | % {
$uid = $_
$note = (Get-ADUser $_ -Properties info).info
$info = "Disabled- 01/15/2014-Last Logon Greater then 90 days "
If ($note -ne $null){
Set-ADUser $_ -replace @{info="$note`r`n$info"}
Disable-ADAccount -Identity $uid
}Else{
Set-ADUser $_ -replace @{info=$info}
Disable-ADAccount -Identity $uid
}
} 

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 40577823
Sorry ..  I thought I had closed this out .. thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now