public/cbb/Start-MBSBackupPlan.ps1

function Start-MBSBackupPlan {
    <#
    .SYNOPSIS
        Run backup plans.
    .DESCRIPTION
        Run backup plans.
    .EXAMPLE
        PS C:\> Start-MBSBackupPlan -Name "Backup VMware"
        Start backup plan by name.
    .EXAMPLE
        PS C:\> Start-MBSBackupPlan -ID ed2e0d37-5ec2-49e1-a381-d2246b3108ec
        Start backup plan by the plan ID.
    .EXAMPLE
        PS C:\> Get-MBSBackupPlan -StorageType Local -PlanType VMware | Start-MBSBackupPlan
        Start VMware backup plans with local backup storages type.
    .EXAMPLE
        PS C:\> Get-MBSBackupPlan -StorageType All -PlanType VMware | Start-MBSBackupPlan
        Start VMware backup plans with all backup storages type.
    .EXAMPLE
        PS C:\>Start-MBSBackupPlan -ID 3a2fde55-9ecd-4940-a75c-d1499b43abda -ForceFull -ForceFullDayOfWeek Friday, Monday
        Run force full on specific day of the week.
    .INPUTS
        System.String[]
        System.String
    .OUTPUTS
        System.String[]
    .NOTES
        Author: Alex Volkov
    .LINK
        https://kb.msp360.com/managed-backup-service/powershell-module/cmdlets/start-mbsbackupplan
    #>


    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipelineByPropertyName)]
        [string]
        $ID,
        #
        [Parameter(ValueFromPipelineByPropertyName)]
        [string]
        $Name,
        #
        [switch]
        $ForceFull,
        #
        [ValidateSet("Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")]
        [string[]]
        $ForceFullDayOfWeek,
        #
        [Parameter(Mandatory=$False, HelpMessage="Master password. Should be specified if configuration is protected by master password. Use -MasterPassword (ConvertTo-SecureString -string ""Your_Password"" -AsPlainText -Force)")]
        [SecureString]
        $MasterPassword
    )
    
    begin {
        $CBB = Get-MBSAgent
    }
    
    process {
        if (Get-MBSAgent -ErrorAction SilentlyContinue) {        
            if ($ID){
                $Arguments += "plan -r $ID"
            }else{
                $Arguments += "plan -r ""$Name"""
            }
            
            if($ForceFull){
                if ($ForceFullDayOfWeek){
                    if((get-date).DayOfWeek -in $ForceFullDayOfWeek){
                        $Arguments += " -ForceFull"
                    }
                }else {
                    $Arguments += " -ForceFull"
                }
            }
            if ($MasterPassword){$Arguments += " -mp """+([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($MasterPassword)))+""""}

            Write-Verbose -Message "Arguments: $Arguments"
            Start-Process -FilePath $CBB.CBBCLIPath -ArgumentList $Arguments -NoNewWindow -Wait
        }
    }
    
    end {
    }
}