core/Resolve-ScopeTagNames.ps1
|
#Requires -Version 7.0 <# .SYNOPSIS Replaces scope tag IDs with display names in an object. .DESCRIPTION Looks for roleScopeTagIds property and replaces each ID with the corresponding display name from the provided scope tag map. .PARAMETER InputObject The object to process. .PARAMETER ScopeTagMap Hashtable mapping scope tag IDs (as strings) to display names. .EXAMPLE $obj = Resolve-ScopeTagNames -InputObject $policy -ScopeTagMap $scopeTagMap #> function Resolve-ScopeTagNames { [CmdletBinding()] param( [Parameter(ValueFromPipeline = $true)] [AllowNull()] $InputObject, [Parameter(Mandatory = $true)] [hashtable]$ScopeTagMap ) #region Validation if ($null -eq $InputObject) { return $null } if (!$ScopeTagMap -or $ScopeTagMap.Count -eq 0) { Write-Verbose 'Scope tag map is empty, returning object unchanged' return $InputObject } #endregion Validation #region Process roleScopeTagIds if ($InputObject.PSObject.Properties['roleScopeTagIds']) { $tagIds = $InputObject.roleScopeTagIds if ($tagIds) { $resolvedNames = [System.Collections.Generic.List[string]]@() foreach ($id in $tagIds) { $idString = $id.ToString() if ($ScopeTagMap.ContainsKey($idString)) { $resolvedNames.Add($ScopeTagMap[$idString]) > $null Write-Verbose "Resolved scope tag ID $idString to $($ScopeTagMap[$idString])" } else { # ID not in map, keep as-is $resolvedNames.Add($idString) > $null Write-Verbose "Scope tag ID $idString not found in map, keeping as-is" } } $InputObject.roleScopeTagIds = $resolvedNames.ToArray() } } #endregion Process roleScopeTagIds return $InputObject } Export-ModuleMember -Function Resolve-ScopeTagNames |