Public/Add-MSPBackupArchivingRule.ps1
Function Add-MSPBackupArchivingRule { <# .SYNOPSIS Create new archiving rule. .DESCRIPTION Create new archiving rule. You could view existing archiving rules using the Get-MSPBackupArchivingRule command (which also prints ID for each rule). .PARAMETER Name Name of the rule, non-empty. .PARAMETER Active Determines whether rule is active. Possible values are 0 (not active) or 1 (active). Default value is 1. .PARAMETER Datasource Datasources to start archiving rule for, separated by comma. Possible values are FileSystem and All. Default value is All. .PARAMETER DayOfWeek Day of week when rule is active. If you use this argument, `-weeks' should also be specified. Possible value is Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday. .PARAMETER DayOfMonth Day (or range of days) when rule is active, separated by comma. This argument is mutually exclusive with `-day-of-week' and `-weeks' arguments. Possible values are numbers between 1 and 31, ranges in the form [N-M] or Last (matching last day of month). Default value is [1-31]. Example: 2,[5-10],20,Last. .PARAMETER Month Months of the year when rule is active, separated by comma. Possible values are Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec and All. Default value is All. Example: Jan,Sep,Dec,May. .PARAMETER Time Time for rule activation. Must be in format hh:mm. Default value is 00:00. .PARAMETER Week Weeks when rule is active, separated by comma. If you use this argument, `-day-of-week' should also be specified. Possible values are 1, 2, 3, 4, Last and All. Example: 1,2,Last. .EXAMPLE Add-MSPBackupArchivingRule Creates a new archiving rule for the MSP Backup client .INPUTS None #> [CmdletBinding(SupportsShouldProcess = $True)] [OutputType('System.String')] Param( [Parameter(Mandatory = $True)] [ValidateNotNullOrEmpty()] [String]$Name, [ValidateSet('0', '1')] [int]$Active = 1, [ValidateSet('FileSystem', 'All')] [String[]]$Datasource = "All", [Parameter( Mandatory = $True, ParameterSetName = "Week" )] [ValidateSet('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')] [String[]]$DayOfWeek, [Parameter( Mandatory = $True, ParameterSetName = "Month" )] [String[]]$DayOfMonth = "1-31", [Parameter( Mandatory = $True, ParameterSetName = "Month" )] [ValidateSet('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'All')] [String[]]$Month = "All", [datetime]$Time, [Parameter( Mandatory = $True, ParameterSetName = "Week" )] [ValidateSet(1, 2, 3, 4, "Last", "All")] [String[]]$Week ) 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.add", "-name $Name", "-active $Active", "-datasource $Datasource" ) If ($DayOfWeek) { $ArgArray += "-day-of-week $DayOfWeek" } If ($DayOfMonth) { $ArgArray += "-day-of-month $DayOfMonth" } If ($Month) { $ArgArray += "-months $Month" } If ($Time) { $ArgArray += "-time $Time" } If ($Week) { $ArgArray += "-weeks $Week" } } Process { If ($PSCmdlet.ShouldProcess("$Name", "Adding Archiving Rule")) { $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) Write-Output $Output } } |