Private/Measure-FatGroupNameLength.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Function Measure-FatGroupNameLength {
    param (
        [parameter(Mandatory = $true)][psobject]$GroupNameList
    )
    $TooLongGroupNames = @()
    foreach ($GroupName in $GroupNameList) {
        $GroupNameLength = $GroupName.Length
        if ($GroupNameLength -gt 120) {
            $TooLongGroupNames += $GroupName
        }
        if ($GroupNameLength -eq 0) {
            Write-Error "No entry for name."
            Throw
        }
    }
    if ($TooLongGroupNames.length -ge 1) {
        Write-Error "The names of the following groups excede the character length (120) in Azure Active Directory: ` "
        foreach ($TooLongGroupName in $TooLongGroupNames) {
            Write-Error "$TooLongGroupName ` "
        }
        Write-Error "Shorten the name(s) and try again."
        Throw
    }
}