functions/inbox/Set-TssInboxMessageRead.ps1
|
function Set-TssInboxMessageRead { <# .SYNOPSIS Mark inbox messages as read or unread .DESCRIPTION Mark one or more inbox messages of the current user as read, or as unread with -Unread. Returns True when the server accepted the change. .PARAMETER TssSession TssSession object created by New-TssSession for authentication .PARAMETER Id Inbox message IDs .PARAMETER Unread Mark the messages as unread instead of read .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Set-TssInboxMessageRead -TssSession $session -Id 112, 113 Mark inbox messages 112 and 113 as read .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Search-TssInboxMessage -TssSession $session -ReadStatus Read -MessageTypeId 4 | Set-TssInboxMessageRead -TssSession $session -Unread Mark every read message of inbox message type 4 as unread .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/inbox/Set-TssInboxMessageRead .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/inbox/Set-TssInboxMessageRead.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [CmdletBinding(SupportsShouldProcess)] [OutputType('System.Boolean')] param ( [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [Thycotic.PowerShell.Authentication.Session] $TssSession, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('MessageId')] [int[]] $Id, [switch] $Unread ) begin { $tssParams = $PSBoundParameters $invokeParams = . $GetInvokeApiParams $TssSession } process { Get-TssInvocation $PSCmdlet.MyInvocation if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { Compare-TssVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation $restResponse = $null $uri = $TssSession.ApiUrl, 'inbox', 'update-read' -join '/' $invokeParams.Uri = $uri $invokeParams.Method = 'POST' $body = @{ data = @{ messageIds = @($Id) read = -not $Unread } } $invokeParams.Body = $body | ConvertTo-Json -Depth 100 if ($PSCmdlet.ShouldProcess("Inbox message: $($Id -join ', ')", "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n")) { Write-Verbose "Performing the operation $($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n" try { $apiResponse = Invoke-TssApi @invokeParams $restResponse = . $ProcessResponse $apiResponse } catch { Write-Warning 'Issue with Set-TssInboxMessageRead request' $err = $_ . $ErrorHandling $err } if ($null -ne $restResponse) { [System.Convert]::ToBoolean($restResponse) } } } else { Write-Warning 'No valid session found' } } } |