04-20-2023 01:23 PM
This script creates a CSV report of system associations (System Group)
How to use:
1. Install the JumpCloud Powershell Module
2. Save the script below to a Powershell file
3. In a PowerShell terminal window run:
# This script will create a csv report list of systems with their associated groups to a CSV file
##### Edit the following variable #####
$csvFilePath = "/Users/kmaranion/systemsWithGroups.csv" # Path to the CSV file. Change this to your own path
##### End Edit #####
$systems = Get-JcSdkSystem
$systems | ForEach-Object {
$systemGroup = Get-JcSdkSystemMember -SystemId $_.Id
$listofSystemGroup = @() # list of group associated with the system
$systemGroup | ForEach-Object {
Get-JcSdkSystemGroup -id $_.Id | Select-Object -ExpandProperty name | ForEach-Object {
$listofSystemGroup += $_
}
}
$systemsWithGroups = @()
$systemsWithGroups += [PSCustomObject]@{
SystemId = $_.Id
SystemHostName = $_.Hostname
# Convert the list of system groups to a string
SystemGroups = $listofSystemGroup -join ','
}
# Export the list of systems with its associated groups to a CSV file
Write-Output "Appending to CSV file the following system: $( $systemsWithGroups | Select-Object -Property SystemId, SystemHostName, SystemGroups)"
$systemsWithGroups | Export-Csv -Path $csvFilePath -Append
}
Example:
New to the site? Take a look at these additional resources:
Ready to join us? You can register here.