Solved

Check accounts in Group and if Disabled , change to Enable

Posted on 2016-08-29
4
27 Views
Last Modified: 2016-08-30
Hi EE

Should this be done differently ? I need to check an AD group and if an account is disabled , I need it to be enabled .
The group will have more than 5000 users and disabled users will vary from 1 - 10 at most .

The script below will work on a small group but on a large group how would you all do it ?

import-module ActiveDirectiry
Get-ADGroupMember -Identity MyGroup | select -expandproperty SamAccountName  | % {Enable-ADAccount  -Identity $_ }

Open in new window

0
Comment
Question by:MilesLogan
  • 2
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41775779
No need to pull 5000 accounts from AD, just to filter out nearly all of them. Filter right at the source:
Import-Module ActiveDirectory
$Group = Get-ADGroup -Identity MyGroup
Get-ADUser -Filter {(Enabled -eq $False) -and (MemberOf -eq $Group.DistinguishedName)} | Enable-ADAccount -Verbose

Open in new window


Edit: added -Verbose to Enable-ADAccount
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 41776470
Thank you oBdA .. works perfect but can you explain to me what -verbose does ? or where I can read about it ?
0
 
LVL 83

Expert Comment

by:oBdA
ID: 41776485
-Verbose is one of the common parameters (like WarningAction, ErrorAction, Whatif, ...); if the cmdlet supports it, it sends verbose output to the verbose stream.
Get-Help -Name about_CommonParameters -ShowWindow

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 41776506
Thank you oBdA ! your are always there to help .
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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 …

757 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

17 Experts available now in Live!

Get 1:1 Help Now