Public/Remove-MSPBackupArchivingRule.ps1
Function Remove-MSPBackupArchivingRule { [CmdletBinding(SupportsShouldProcess = $true)] [OutputType('System.String')] Param( [Parameter(Mandatory=$True)] [Int]$Id ) Begin { Write-Verbose ('{0}:: Function started' -f $MyInvocation.MyCommand) $stdOutTempFile = [System.IO.Path]::GetTempFileName() $stdErrTempFile = [System.IO.Path]::GetTempFileName() $ArgArray = @( "-machine-readable", "-non-interactive", "control.archiving.remove" "-id $Id" ) } Process { If ($PSCmdlet.ShouldProcess("Id: $Id","Remove Archiving Rule")) { $StartProcessParams = @{ FilePath = $Script:CmdPath ArgumentList = $ArgArray Wait = $true NoNewWindow = $true PassThru = $true RedirectStandardOutput = $stdOutTempFile RedirectStandardError = $stdErrTempFile ErrorAction = "SilentlyContinue" } $StartExe = Start-Process @StartProcessParams $ClientToolExitCode = $StartExe.ExitCode $ClientToolStandardOutput = Get-Content -Path $stdOutTempFile | Out-String $ClientToolStandardOutput = $ClientToolStandardOutput.Trim() $ClientToolStandardError = Get-Content -Path $stdErrTempFile | Out-String $ClientToolStandardError = $ClientToolStandardError.Trim() If ($stdOutTempFile -or $stdErrTempFile) { Remove-Item @RemoveItemParams } $ArgArray | Out-Null $ClientToolExitCode | Out-Null If ($null -ne $ClientToolStandardError) { $Output = $ClientToolStandardError } Else { $Output = $ClientToolStandardOutput } } } End { Write-Verbose ('{0}:: Function ended' -f $MyInvocation.MyCommand) Return $Output } } |