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

x
?
Solved

Check accounts in Group and if Disabled , change to Enable

Posted on 2016-08-29
4
Medium Priority
?
35 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
[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
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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 85

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
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

688 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