Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Disable multiple AD accounts with powershell

Posted on 2015-01-15
2
Medium Priority
?
234 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

886 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