Skip to content

Commit 19858b3

Browse files
committed
PSSA Cleanup
1 parent f601ec2 commit 19858b3

34 files changed

+1696
-1845
lines changed

Active Directory/AD Groups/Archive-ObsoleteGroups.ps1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
# Author: Sam Erde
66
#
77
# Created: 11/04/2014
8-
# Description: Read a list of obsolete groups from a text file, export the members to a separate text file for each group,
8+
# Description: Read a list of obsolete groups from a text file, export the members to a separate text file for each group,
99
# and then empty the obsolete groups. They can be deleted after a week or two to prove they are no longer used.
1010
# The empty groups are also moved to the "Obsolete Groups" OU.
1111
#
1212
# DO NOT RUN TWICE ON THE SAME FILE OR THE ARCHIVE WILL BE OVERWRITTEN!
1313
#
14-
# To Do:
14+
# To Do:
1515
# Add error handling
1616
# Prompt for a job name at each run so their is a separate archive folder for each job to help prevent an archive from being overwritten.
1717
# Add handling of group names to it can discover DNs if needed. This may require a specific format within the input file, such as group DNs there.
@@ -22,25 +22,24 @@
2222
Import-Module ActiveDirectory
2323

2424
#Set the Active Directory server name that will be used. Using a serverless domain name here may also work.
25-
$Domain = ""
25+
$Domain = ''
2626

2727
#Read in the CSV or text file of group names.
2828
$File = Get-Content -Path C:\Scripts\ObsoleteGroups\ObsoleteGroups.csv
2929

3030
#Loop through each line of the text file and run the following commands for each line:
31-
Foreach ($Group in $File)
32-
{
31+
Foreach ($Group in $File) {
3332
#Get the members of each group (recursively in case groups are nested) in the specified domain or domain controller.
3433
#Select the name of each member within the group and then write each name to a CSV file. Each CSV file is named with the name of each security group.
3534
Get-ADGroupMember -Server $Domain -Identity $Group -Recursive | Export-Csv -Path "C:\Scripts\ObsoleteGroups\Archive\$group.csv" -NoTypeInformation
3635

3736
<# * * * * * * * * * *
38-
This section will require special customization until we further develop the script to pull the full group DN.
37+
This section will require special customization until we further develop the script to pull the full group DN.
3938
In the interest of time today, I have hard coded some of the information.
4039
* * * * * * * * * *
4140
/#>
42-
.\Remove-AllGroupMembers.ps1 -group "CN=$Group" -ou "OU=" -domain "DC="
43-
Move-ADObject -Server $Domain -Identity "CN=ps,DC=" -TargetPath ""
41+
.\Remove-AllGroupMembers.ps1 -group "CN=$Group" -ou 'OU=' -domain 'DC='
42+
Move-ADObject -Server $Domain -Identity 'CN=ps,DC=' -TargetPath ''
4443
}
4544

4645
#Copy and rename the CSV file with a timestamp to keep as a record of run history.

0 commit comments

Comments
 (0)