Skip to content

Manage Group Memberships

Overview

This guide covers two JIT group membership patterns using the Britive Access Broker:

  • Single group — adds the requesting user’s own AD account to a group at checkout, removes it at checkin.
  • Admin (-a) account with group — creates or re-uses the user’s dedicated admin account (e.g. jdoe-a), adds it to a group at checkout, and removes it at checkin.

Before You Begin

  • The Britive Access Broker is running on a domain-joined Windows VM (see Getting Started)
  • The broker gMSA has Write member delegated on the target group OU
  • For the -a pattern: the gMSA also has Create user delegated on the target accounts OU
  • RSAT Active Directory module installed on the broker host

Single Group Membership

Full scripts: Active Directory/permissions/add-user-to-group/

The requesting user’s own AD account is added to a named security group for the duration of the checkout session.

Environment variables injected by Britive: user (UPN of requesting user), group (AD group name)

Checkout routine

Import-Module ActiveDirectory

$adUser  = Get-ADUser  -Filter "UserPrincipalName -eq '$($env:user)'" -ErrorAction Stop
$adGroup = Get-ADGroup -Identity $env:group -ErrorAction Stop

Add-ADGroupMember -Identity $env:group -Members $adUser -ErrorAction Stop
Write-Output "User '$($env:user)' added to group '$($env:group)'."

Checkin routine

Import-Module ActiveDirectory

$adUser  = Get-ADUser  -Filter "UserPrincipalName -eq '$($env:user)'" -ErrorAction Stop
$adGroup = Get-ADGroup -Identity $env:group -ErrorAction Stop

Remove-ADGroupMember -Identity $env:group -Members $adUser -ErrorAction Stop -Confirm:$false
Write-Output "User '$($env:user)' removed from group '$($env:group)'."

Variables

VariableValueSystem defined
userInjected from Britive — the requesting user’s UPNYes
groupName of the AD security group, e.g. SQL-DBAsNo — set on the permission or profile

Admin (-a) Account with Group Membership

Full scripts: Active Directory/permissions/add-group-a-account/

This pattern is for privileged access where users have a dedicated admin account alongside their standard account. The convention is jdoe-a for user jdoe@contoso.com, controlled by a configurable prefix variable.

At checkout:

  1. The -a account is created if it does not exist (first-time self-provisioning)
  2. The account is added to the target group

At checkin:

  • The account is removed from the group
  • The account itself persists (no deletion) but holds no group memberships between sessions

Environment variables: user (UPN), group (group name), prefix (account suffix, e.g. -a)

Checkout routine

Derive admin account name and create if needed:

$Username = $env:prefix + ($env:user -split "@")[0]

$User = Get-ADUser -Filter { SamAccountName -eq $Username } -ErrorAction SilentlyContinue

if (-not $User) {
    $password = -join ((1..16) | ForEach-Object { $chars[(Get-Random -Maximum $chars.Length)] })
    New-ADUser -Name $Username -SamAccountName $Username -UserPrincipalName $env:user `
               -AccountPassword (ConvertTo-SecureString $password -AsPlainText -Force) -Enabled $true
}

Add to group:

$Group = Get-ADGroup -Filter { Name -eq $env:group } -ErrorAction SilentlyContinue
if ($Group) {
    Add-ADGroupMember -Identity $env:group -Members $Username
    Write-Output "Added $Username to group $($env:group)."
} else {
    Write-Error "Group '$($env:group)' does not exist."; exit 1
}

Checkin routine

$Username = ($env:user -split "@")[0] + $env:prefix

$IsMember = Get-ADGroupMember -Identity $env:group -Recursive |
            Where-Object { $_.SamAccountName -eq $Username }

if ($IsMember) {
    Remove-ADGroupMember -Identity $env:group -Members $Username -Confirm:$false
    Write-Output "Removed $Username from group $($env:group)."
}

Variables

VariableExample valueNotes
userInjectedBritive UPN of the requesting user
groupServer-AdminsAD security group name
prefix-aPrepended to username to derive the admin account SamAccountName

The -a account is created on first checkout and reused on subsequent sessions — it is never deleted. To also rotate the account password at each checkout, use Rotate Admin Accounts instead.


Configure in Britive

Create a permission

Go to Resource Manager → Resource Type Permissions → New Permission. Set Language to PowerShell.

For single group membership, paste checkout.ps1 and checkin.ps1.

For the -a account, paste checkout.ps1 and checkin.ps1.

Declare variables — mark user as system-defined; set group (and prefix for the -a account) as static values:

VariableSystem definedNotes
userYesInjected automatically
groupNoAD security group name
prefixNo-a account only — e.g. -a

Create a profile

Go to Resource Manager → Profiles → New Profile. Set an expiration. Under Associations, select the resource label(s) covering your AD domain resources. Under Permissions, add the permission above.

Add a policy

Under Policies, assign members (users or tags) and configure approval conditions.


Verify

After checking out the profile in the Britive console:

# Confirm the user or -a account was added
Get-ADGroupMember -Identity "Server-Admins" | Select-Object Name, SamAccountName

After checking in (or session expires):

# Confirm the membership was removed
Get-ADGroupMember -Identity "Server-Admins" | Select-Object Name, SamAccountName

Troubleshoot

SymptomCauseFix
The group does not existGroup name mismatch or wrong OUConfirm the exact Name attribute value from ADUC
The user does not existUPN format mismatchConfirm $env:user is a UPN, not a SamAccountName
Access denied on Add-ADGroupMembergMSA missing Write member delegationRe-run the dsacls delegation from Getting Started
Account not created on first checkoutgMSA missing Create user delegationDelegate CC;user on the managed accounts OU
Last updated on