diff --git a/Modules/CippExtensions/Public/PwPush/New-PwPushLink.ps1 b/Modules/CippExtensions/Public/PwPush/New-PwPushLink.ps1 index 0a29234f0071..566bf8c3cb45 100644 --- a/Modules/CippExtensions/Public/PwPush/New-PwPushLink.ps1 +++ b/Modules/CippExtensions/Public/PwPush/New-PwPushLink.ps1 @@ -1,11 +1,11 @@ function New-PwPushLink { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] Param( $Payload ) $Table = Get-CIPPTable -TableName Extensionsconfig $Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json).PWPush - if ($Configuration.Enabled) { + if ($Configuration.Enabled -eq $true) { Set-PwPushConfig -Configuration $Configuration $PushParams = @{ Payload = $Payload @@ -14,15 +14,17 @@ function New-PwPushLink { if ($Configuration.ExpireAfterViews) { $PushParams.ExpireAfterViews = $Configuration.ExpireAfterViews } if ($Configuration.DeletableByViewer) { $PushParams.DeletableByViewer = $Configuration.DeletableByViewer } try { - $Link = New-Push @PushParams | Select-Object Link, LinkRetrievalStep - if ($Configuration.RetrievalStep) { - $Link.Link = $Link.LinkRetrievalStep + if ($PSCmdlet.ShouldProcess('Create a new PwPush link')) { + $Link = New-Push @PushParams + if ($Configuration.RetrievalStep) { + return $Link.LinkRetrievalStep + } + return $Link.Link } - $Link | Select-Object -ExpandProperty Link } catch { $LogData = [PSCustomObject]@{ - 'Response' = $Link - 'Exception' = Get-CippException -Exception $_ + 'Response' = $Link + 'Exception' = Get-CippException -Exception $_ } Write-LogMessage -API PwPush -Message "Failed to create a new PwPush link: $($_.Exception.Message)" -Sev 'Error' -LogData $LogData throw 'Failed to create a new PwPush link, check the log book for more details'