Get User AD Group Membership

Gets a Users AD group membership

Version: 1.3.8
Created: 2019-04-11T12:47:37.723
Modified: 2019-04-11T19:00:06.267
Creator:
Downloads: 189
Tags:
The Script Copy Script Copied to clipboard

<# .SYNOPSIS Gets the selected user(s) Active Directory groups .PARAMETER UserName The name of the user to be view group memberships - automatically supplied by CU #>

$ErrorActionPreference = “Stop”

If ( (Get-Module -Name ActiveDirectory -ErrorAction SilentlyContinue) -eq $null )
{
Try {
Import-Module ActiveDirectory
} Catch {
# capture any failure and display it in the error section, then end the script with a return
# code of 1 so that CU sees that it was not successful.
Write-Error “Not able to load the Module” -ErrorAction Continue
Write-Error $Error[1] -ErrorAction Continue
Exit 1
}
}

# Because this is the main function of the script it is put into a try/catch frame so that any errors will be
# handled in a ControlUp-friendly way.

Try {
Get-ADPrincipalGroupMembership -Identity $args[0] | select Name
} Catch {
# capture any failure and display it in the error section, then end the script with a return
# code of 1 so that CU sees that it was not successful.
Write-Error $Error[0] -ErrorAction Continue
Exit 1
}

Write-Host “The operation completed successfully.”

START YOUR TRIAL

Get Your Download Link

Gain access to ControlUp from your PC. Register and get a link to start your Free Trial.