PowerShell Genie

Audit users with risky delegation flags

Script 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-ADUser requests the delegation-related properties explicitly because they are not returned by default.

The script

1PS> Get-ADUser -Filter 'Enabled -eq $true' -Properties TrustedForDelegation,TrustedToAuthForDelegation,AccountNotDelegated |
2PS> Where-Object { $_.TrustedForDelegation -or $_.TrustedToAuthForDelegation } |
3PS> Select-Object SamAccountName,Enabled,TrustedForDelegation,TrustedToAuthForDelegation,AccountNotDelegated |
4PS> Sort-Object SamAccountName

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 SamAccountName Enabled TrustedForDelegation TrustedToAuthForDelegation AccountNotDelegated
    2 -------------- ------- -------------------- -------------------------- -------------------
    3 jsmith True
    4 ajones True
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-ADUser -Filter 'Enabled -eq $true' -Properties TrustedForDelegation,TrustedToAuthForDelegation,AccountNotDelegated | Where-Object { $_.TrustedForDelegation -or $_.TrustedToAuthForDelegation } | Select-Object SamAccountName,Enabled,TrustedForDelegation,TrustedToAuthForDelegation,AccountNotDelegated | Sort-Object SamAccountName
    1. Stage 1Get-ADUser-Filter -Properties
    2. Stage 2Where-ObjectPositional values or no named parameters
    3. Stage 3Select-ObjectPositional values or no named parameters
    4. Stage 4Sort-ObjectPositional values or no named parameters

      How it works

      Get-ADUser requests the delegation-related properties explicitly because they are not returned by default. The filter keeps the directory query broad enough to remain readable, then Where-Object keeps only enabled accounts with delegation enabled. The output is a review list; it does not change an account.

      Adapting it

      Add SearchBase to scope the review to a tier or OU. For service accounts, join the result with SPN data rather than assuming every delegated user is equally exposed.

      Primary documentation

      Where-Object reference · Select-Object reference · Sort-Object reference

      Continue
      Genie guideAudit users with risky delegation flags

      Get-ADUser requests the delegation-related properties explicitly because they are not returned by default.