Created
June 26, 2023 13:54
-
-
Save joshfinley/61695fc58468f9a2a184f624a47da270 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module ActiveDirectory | |
# Specify the path to the CSV file | |
$csvPath = "input.csv" | |
# Initialize an empty array to store the results | |
$results = @() | |
# Read the CSV file and iterate over each row | |
$csvData = Import-Csv -Path $csvPath | |
foreach ($row in $csvData) { | |
# Retrieve the group name from the 'GroupName' column | |
$groupName = $row.GroupName | |
# Retrieve all computer objects in the group | |
$groupMembers = Get-ADGroupMember -Identity $groupName -Recursive | | |
Where-Object { $_.objectClass -eq 'computer' } | | |
Select-Object @{Name="GroupName"; Expression={$groupName}}, Name | |
# Add the group members to the results array | |
$results += $groupMembers | |
} | |
# Output the results to a single CSV file | |
$outputFilePath = "GroupComputerObjects.csv" | |
$results | Export-Csv -Path $outputFilePath -NoTypeInformation | |
Write-Host "Computer objects for all groups exported to '$outputFilePath'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment