Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Remove old SIDS from multiple AD groups with powershell

Posted on 2016-09-28
2
Medium Priority
?
188 Views
Last Modified: 2016-09-29
Hi EE

I have a list of old SIDS I need to remove from groups but instead of doing one at a time , I wanted to add all the SIDS and groups
to a CSV file and remove them faster ...

I was thinking something like this ... but I need help completing it or if someone already has this .

$sids = import-csv .\RemoveSIDS.csv
Foreach ($sid in $sids) {Set-ADGroup $sids -remove @{SIDHistory=$sid.value} }


What would my CSV file headers be ? how do I reference that in the script ?
one column would have the SID and the other column would be the group name that it needs to remove the SID from .

this does one at a time .
Set-ADGroup <Groupname> -remove @{sidhistory="S-1-5-21-xxxxxxxxx-xxxxxxxxx-xxxxxxxxxx-xxxx"}
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 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 41820799
Try...
Import-csv c:\input.csv | % {Set-ADGroup $_.Group -remove @{sidhistory=$_.Sid}}

Open in new window

Csv format
Group,Sid
GroupA,S-1-5-21-xxxxxxxxx-xxxxxxxxx-xxxxxxxxxx-xxxx
GroupB,S-1-5-21-xxxxxxxxx-xxxxxxxxx-xxxxxxxxxx-xxxx

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 41822790
perfect !
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here's a look at newsworthy articles and community happenings during the last month.
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

618 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