11-10-2022 02:16 PM
This script creates a CSV report of user associations (Group and Systems)
How to use:
1. Install the JumpCloud Powershell Module
2. Save the contents of the script example to a file on a system.
3. In a PowerShell terminal window run:
Script
# Get everyone from a group
$users = Get-JcSdkUser
# Initialize an empty list
$list = @()
# For each user
foreach ($user in $users)
{
$userDetails = Get-jcsdkUser -Id $user.id
# Get System Associations
$systemAssociations = Get-JcSdkUserTraverseSystem -UserId $user.Id
# Get Group Associations
$groupAssociations = Get-JcSdkUserMember -UserId $user.Id
# Clear variables
$foundSystem = ""
$foundGroup = ""
# For each system association
foreach ($systemAssociation in $systemAssociations)
{
$foundSystem += $systemAssociation.Id + ';'
}
# For each group association
foreach ($groupAssociation in $groupAssociations)
{
$foundGroup += $groupAssociation.Id + ';'
}
# populate the rows
$list += [PSCustomObject]@{
userID = $user.Id;
username = $userDetails.Username;
userState = $userDetails.State
associatedSystems = $foundSystem
associatedGroups = $foundGroup
}
}
# Write out the report
$list | ConvertTo-Csv | Out-File Report-UserToGroupAssociation.csv
New to the site? Take a look at these additional resources:
Ready to join us? You can register here.