Solved

Check accounts in Group and if Disabled , change to Enable

Posted on 2016-08-29
4
31 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article runs through the process of deploying a single EXE application selectively to a group of user.
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 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