public/cbb/New-MBSRecoveryDisk.ps1

function New-MBSRecoveryDisk {
    <#
    .SYNOPSIS
    Create recovery USB or iso image
     
    .DESCRIPTION
    Create recovery USB drive ot ISO image for bare-metal image-based restore.
     
    .PARAMETER DestinationUSBDrive
    Specify destination USB drive
     
    .PARAMETER DestinationISOPath
    Specify destination iso-image path
     
    .PARAMETER Password
    Settings password. Use -Password (ConvertTo-SecureString -string "Your_Password" -AsPlainText -Force)
     
    .PARAMETER AddSystemDrivers
    Add drivers installed in system
     
    .PARAMETER AdditionalDriversPath
    Add drivers from specified folder
     
    .PARAMETER ScratchSpace
    Sets the available scratch space, in megabytes
     
    .PARAMETER RADirectory
    Remote access installation directory
     
    .PARAMETER NoPrompt
    Skip 'press any key to boot from cd/dvd' at startup
     
    .PARAMETER MasterPassword
    Master password. Should be specified if configuration is protected by master password. Use -MasterPassword (ConvertTo-SecureString -string "Your_Password" -AsPlainText -Force)
     
    .EXAMPLE
    New-MBSRecoveryUSBISO -DestinationISOPath D:\iso\MSP360Restore.iso
 
    Create recovery ISO file with default settings.
 
    .EXAMPLE
    New-MBSRecoveryUSBISO -DestinationUSBDrive D
 
    Create recovery USB drive with default settings.
 
    .EXAMPLE
    New-MBSRecoveryUSBISO -DestinationUSBDrive D
 
    Create recovery USB drive with default settings.
     
    .INPUTS
        None.
    .OUTPUTS
        None.
    .NOTES
        Author: Alex Volkov
    .LINK
        https://kb.msp360.com/managed-backup-service/powershell-module/cmdlets/backup-agent/New-MBSRecoveryDisk
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true, HelpMessage="Specify destination USB drive", ParameterSetName='USB')]
        [ValidatePattern("[A-Z]")]
        [String]
        $DestinationUSBDrive,
        [Parameter(Mandatory=$true, HelpMessage="Specify destination iso-image path", ParameterSetName='ISO')]
        [String]
        $DestinationISOPath,
        [Parameter(Mandatory=$false, HelpMessage="Settings password. Use -Password (ConvertTo-SecureString -string ""Your_Password"" -AsPlainText -Force)")]
        [SecureString]
        $Password,
        [Parameter(Mandatory=$false, HelpMessage="Add drivers installed in system")]
        [Switch]
        $AddSystemDrivers,
        [Parameter(Mandatory=$false, HelpMessage="Add drivers from specified folder")]
        [String]
        $AdditionalDriversPath,
        [Parameter(Mandatory=$false, HelpMessage="Sets the available scratch space, in megabytes")]
        [ValidateSet("0", "256", "512")]
        [String]
        $ScratchSpace,
        [Parameter(Mandatory=$false, HelpMessage="Remote access installation directory")]
        [String]
        $RADirectory,
        [Parameter(Mandatory=$false, HelpMessage="Skip 'press any key to boot from cd/dvd' at startup")]
        [Switch]
        $NoPrompt,
        [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 {
        if (-not ($CBB = Get-MBSAgent)){
            break
        }
    }
    
    process {
        function Set-Argument {
            if ($DestinationUSBDrive){$Argument += " -d $DestinationUSBDrive"+":\"}
            if ($DestinationISOPath){$Argument += " -d ""$DestinationISOPath"" -iso"}
            if ($Password){$Argument += " -p """+([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)))+""""}
            if ($AddSystemDrivers){$Argument += " -id"}
            if ($AdditionalDriversPath){$Argument += " -iad ""$AdditionalDriversPath"""}
            if ($ScratchSpace){$Argument += " -ss $ScratchSpace"}
            if ($RADirectory){$Argument += " -d ""$RADirectory"""}
            if ($NoPrompt){$Argument += " -no-prompt"}
            if ($MasterPassword){$Argument += " -mp """+([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($MasterPassword)))+""""}
                
            return $Argument
        }

        if($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent){
            $Arguments = 'createrecovery -output full'
        }else{
            $Arguments = 'createrecovery -output short'
        }
        $Arguments += Set-Argument
        Write-Verbose -Message "Arguments: $Arguments"
        Write-Verbose -Message $PSCmdlet.ParameterSetName
        Start-Process -FilePath $CBB.CBBCLIPath -ArgumentList $Arguments -Wait -NoNewWindow
    }
    
    end {
        
    }
}