Private/Get-NSPConditionalAccessCountryName.ps1
|
function Get-NSPConditionalAccessCountryName { <# .SYNOPSIS A two-letter country code's English name (HR -> Croatia), or the code when Windows does not know it. .DESCRIPTION -ForObjectName gives a form safe for group names: ASCII letters and digits only, each word capitalized and joined (GB -> UnitedKingdom, BA -> BosniaAndHerzegovina, CI -> CoteDIvoire). Names come from .NET's RegionInfo, which is the same in Windows PowerShell 5.1 and 7. #> [CmdletBinding()] [OutputType([string])] param( [Parameter(Mandatory)][string]$Code, [switch]$ForObjectName ) $iso = $Code.ToUpperInvariant() $name = $null if ($iso -match '^[A-Z]{2}$') { $name = try { ([System.Globalization.RegionInfo]::new($iso)).EnglishName } catch { $null } } if (-not $name) { return $iso } if (-not $ForObjectName) { return $name } $plain = -join @($name.Replace('&', ' and ').Normalize([Text.NormalizationForm]::FormD).ToCharArray() | Where-Object { [Globalization.CharUnicodeInfo]::GetUnicodeCategory($_) -ne [Globalization.UnicodeCategory]::NonSpacingMark }) $words = @($plain -split '[^A-Za-z0-9]+' | Where-Object { $_ }) $joined = -join @($words | ForEach-Object { $_.Substring(0, 1).ToUpperInvariant() + $_.Substring(1) }) if ($joined) { $joined } else { $iso } } |