|
| 1 | +function Convert-QuarantinePermissionsValue { |
| 2 | + param ( |
| 3 | + [Parameter(Mandatory = $true, Position=0)] |
| 4 | + [ValidateNotNullOrEmpty()] |
| 5 | + [ValidateScript( |
| 6 | + {$_ -is [String] ? $true : $_ -is [Hashtable] ? $true : $false}, |
| 7 | + ErrorMessage = "Input must be a string or hashtable." |
| 8 | + )] |
| 9 | + $InputObject |
| 10 | + ) |
| 11 | + |
| 12 | + #Converts string value with EndUserQuarantinePermissions received from Get-QuarantinePolicy |
| 13 | + if ($InputObject -is [String]) { |
| 14 | + try { |
| 15 | + # Remove square brackets and split into lines |
| 16 | + $InputObject = $InputObject.Trim('[', ']') |
| 17 | + $hashtable = @{} |
| 18 | + $InputObject -split "`n" | ForEach-Object { |
| 19 | + $key, $value = $_ -split ":\s*" |
| 20 | + $hashtable[$key.Trim()] = [System.Convert]::ToBoolean($value.Trim()) |
| 21 | + } |
| 22 | + return $hashtable |
| 23 | + } |
| 24 | + catch { |
| 25 | + $ErrorMessage = Get-NormalizedError -Message $_.Exception.Message |
| 26 | + throw "Convert-QuarantinePermissionsValue: Failed to convert string to hashtable. Error: $ErrorMessage" |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + #Converts hashtable with selected end user quarantine permissions to decimal value used by EndUserQuarantinePermissionsValue property in New-QuarantinePolicy and Set-QuarantinePolicy |
| 31 | + elseif ($InputObject -is [Hashtable]) { |
| 32 | + try { |
| 33 | + $EndUserQuarantinePermissionsValue = 0 |
| 34 | + $EndUserQuarantinePermissionsValue += ([int]$InputObject.PermissionToViewHeader ?? 0 ) * 128 |
| 35 | + $EndUserQuarantinePermissionsValue += ([int]$InputObject.PermissionToDownload ?? 0 ) * 64 |
| 36 | + $EndUserQuarantinePermissionsValue += [int]$InputObject.PermissionToAllowSender * 32 |
| 37 | + $EndUserQuarantinePermissionsValue += [int]$InputObject.PermissionToBlockSender * 16 |
| 38 | + $EndUserQuarantinePermissionsValue += [int]$InputObject.PermissionToRequestRelease * 8 |
| 39 | + $EndUserQuarantinePermissionsValue += [int]$InputObject.PermissionToRelease * 4 |
| 40 | + $EndUserQuarantinePermissionsValue += [int]$InputObject.PermissionToPreview * 2 |
| 41 | + $EndUserQuarantinePermissionsValue += [int]$InputObject.PermissionToDelete * 1 |
| 42 | + return $EndUserQuarantinePermissionsValue |
| 43 | + } |
| 44 | + catch { |
| 45 | + $ErrorMessage = Get-NormalizedError -Message $_.Exception.Message |
| 46 | + throw "Convert-QuarantinePermissionsValue: Failed to convert hashtable to QuarantinePermissionsValue. Error: $ErrorMessage" |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments