Public/Get-MaskMapping.ps1
|
function Get-MaskMapping { <# .SYNOPSIS Reads the current mappings from the mapping file. .DESCRIPTION Returns the entries in the mapping JSON file as Key/Value objects, sorted by key, so the results display as a table and can be piped to Where-Object, Add-MaskMapping, etc. Optionally filter to specific keys. .PARAMETER Key One or more keys to return. Supports wildcards. When omitted, all entries are returned. .PARAMETER MappingFile Path to the mapping JSON file. Defaults to MaskSensitiveData_Map.json in the user's profile. .EXAMPLE Get-MaskMapping Lists all mappings in the default mapping file. .EXAMPLE Get-MaskMapping -Key 'Cont*' Returns mappings whose key matches the wildcard 'Cont*'. .LINK Add-MaskMapping .LINK Remove-MaskMapping #> [CmdletBinding()] param( [Parameter(Position = 0)] [string[]]$Key, [string]$MappingFile = (Join-Path $env:USERPROFILE 'MaskSensitiveData_Map.json') ) $map = Import-Mapping -MappingFile $MappingFile -Require $keys = $map.Keys | Sort-Object if ($Key) { $keys = $keys | Where-Object { $candidate = $_ $Key | Where-Object { $candidate -like $_ } } } foreach ($k in $keys) { [pscustomobject]@{ Key = $k Value = $map[$k] } } } |