Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable multiple AD accounts with powershell

Posted on 2015-01-15
2
Medium Priority
?
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

705 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