Public/Add-MSPBackupScript.ps1

Function Add-MSPBackupScript {
    <#
        .SYNOPSIS
            Create new script.
        .DESCRIPTION
            Scripts could be used in combination with schedules as pre- and post-backup actions. To do this, add new (or
            find existing) script and provide its ID to `control.schedule.add' or `control.schedule.modify' command.
 
            You could view existing scripts using `control.script.list' command (which also prints ID for each script).
        .PARAMETER Path
            Path to file with non-empty script body.
        .PARAMETER Name
            Name of the script, non-empty.
        .PARAMETER Password
            System user password.
        .PARAMETER User
            System user to run script as.
        .PARAMETER FailSessionOnError
            Whether backup session should fail on script error, when used as pre-backup action. Possible values are 0 (do
            not fail) or 1 (fail). Default value is 0.
        .PARAMETER TimeOut
            Execution timeout, in seconds. Default value is 0 (no timeout).
        .INPUTS
            None
        .OUTPUTS
            None
        .EXAMPLE
            Add-MSPBackupScript
        .LINK
            about_functions_advanced
        .LINK
            about_CommonParameters
    #>

    [CmdletBinding(SupportsShouldProcess = $true)]
    [OutputType('System.String')]
    Param(
        [Parameter(Mandatory = $true)]
        [System.IO.FileInfo]$Path,
        [Parameter(Mandatory = $true)]
        [String]$Name,
        [Parameter(Mandatory = $true)]
        [securestring]$Password,
        [Parameter(Mandatory = $true)]
        [String]$User,
        [bool]$FailSessionOnError = $false,
        [Int]$TimeOut = 0
    )
    Begin {
        Write-Verbose ('{0}:: Function started' -f $MyInvocation.MyCommand)
        $stdOutTempFile = [System.IO.Path]::GetTempFileName()
        $stdErrTempFile = [System.IO.Path]::GetTempFileName()
    }
    Process {
        Write-Verbose ('{0}:: Getting status' -f $MyInvocation.MyCommand)
        $Status = & $Script:CmdPath -machine-readable control.script.add
    }
    End {
        Write-Verbose ('{0}:: Function ended' -f $MyInvocation.MyCommand)
        Return $Status
    }
}