Private/Remove-SensitiveData.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
25
function Remove-SensitiveData {
    param (
        [parameter(ValueFromPipeline = $True)]
        $InputObject,
        $SensitiveProperties = @('Uri', 'Token'),
        $ForceVerbose = $Script:PSSlack.ForceVerbose
    )
    process {
        if($ForceVerbose) {
            return $InputObject
        }
        if($InputObject -is [hashtable] -or ($InputObject.Keys.Count -gt 0 -and $InputObject.Values.Count -gt 0)) {
            $Output = [hashtable]$($InputObject.PSObject.Copy())
            foreach($Prop in $SensitiveProperties) {
                if($InputObject.ContainsKey($Prop)) {
                    $Output[$Prop] = 'REDACTED'
                }
            }
            $Output
        }
        else {
            $InputObject | Select-Object -Property * -ExcludeProperty $SensitiveProperties
        }
    }
}