Public/Set-MSPBackupArchivingRule.ps1
Function Set-MSPBackupArchivingRule { [CmdletBinding(SupportsShouldProcess = $true)] [OutputType('System.String')] Param( [Parameter(Mandatory=$True)] [Int]$Id, [ValidateSet('0','1')] [int]$Active, [ValidateSet('FileSystem','All')] [String[]]$Datasource, [Parameter(ParameterSetName = "Week")] [ValidateSet('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')] [String[]]$DayOfWeek, [Parameter(ParameterSetName = "Month")] [String[]]$DayOfMonth, [Parameter(ParameterSetName = "Month")] [ValidateSet('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'All')] [String[]]$Month, [String[]]$Name, [DateTime]$Time, [Parameter(ParameterSetName = "Week")] [String[]]$Week ) Begin { Write-Verbose ('{0}:: Function started' -f $MyInvocation.MyCommand) $ArgArray = @( "-machine-readable", "-non-interactive", "control.archiving.modify" "-id $Id" ) If ($Active) { $ArgArray += "-active $Active" } If ($Datasource) { $ArgArray += "-datasources $Datasource" } If ($DayOfWeek) { $ArgArray += "-day-of-week $DayOfWeek" } If ($DayOfMonth) { $ArgArray += "-day-of-month $DayOfMonth" } If ($Month) { $ArgArray += "-months $Month" } If ($Name) { $ArgArray += "-name $Name" } If ($Time) { $ArgArray += "-time $Time" } If ($Week) { $ArgArray += "-weeks $Week" } } Process { If($PSCmdlet.ShouldProcess("Id: $Id","Modify 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 } } |