mystikal1000
asked on
Removing multiple AD groups
I need a Powershell script that will delete all Ad Groups in a text file with verification. I have 100's of groups in the text file that include local and global groups. I will award points asap.
Thanks!
Thanks!
Alternatively in order to have a clean environment you can also perform the below steps
Query to verify the group exists
Delete all members from the group
Then delete the group from AD
Query to verify the group exists
Delete all members from the group
Then delete the group from AD
gc files.txt | % {
$gname = $_
Get-ADGroupMember $gname | % {Remove-ADGroupMember $_ $_ -Confirm:$false}
get-adgroup -filter 'Name -like $gname | remove-adgroup
}
ASKER
I don't need a confirmation. Your second script will work, but...
I tried running the 2nd script, but got this error...
I tried running the 2nd script, but got this error...
get-adgroup -filter 'Name -like $gname | remove-adgroup}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: '.
At C:\test\deletegroups.ps1:1 char:19
+ gc groups.txt | % {
+ ~
Missing closing '}' in statement block.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Np happy to help, thanks for helping me jumpstart my brain after the holidays.
Do you need a prompt to answer Yes or No before completing the step ?
Easy one liner
Open in new window
Above will remove without prompting