Solved

Disable multiple AD accounts with powershell

Posted on 2015-01-15
2
113 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

821 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