Share via

Exclude from powershell script

Thulani Shabalala 21 Reputation points
2021-07-07T09:13:26.95+00:00

I am thinking of excluding council members from the script below, meaning excluding the "Department" = Council Members , may you please assist me on how I can update the following script to achieve this:

Import-Module ActiveDirectory

Update Staff extensionAttribute15 in BFN VC

$Users = Get-ADUser -Filter * -SearchBase "OU=....,OU=....,DC=....,DC=....,DC=...."
foreach($User in $Users)
{
# Set extensionAttribute15 for Staff
$User.extensionAttribute15 = "Staff"
# Update AD account
Set-ADUser -Instance $User
}

The goal is to exclude the Department called "Council Members" from the above script.

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

Anonymous
2021-07-07T12:14:49.53+00:00

Hi,

You can filter out the users like below.

$Users = Get-ADUser -Filter "Department -ne 'Council Members'"  -SearchBase "OU=VC,OU=bfn,DC=cut,DC=ac,DC=za"  

Best Regards,
Ian Xue

============================================

If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.