public/cbb/Remove-MBSBackupPlan.ps1
function Remove-MBSBackupPlan { <# .SYNOPSIS Removes existing backup plan .DESCRIPTION Removes MBS backup plan either by it's Name or ID. .PARAMETER Name Backup plan name .PARAMETER ID Backup plan ID .PARAMETER MasterPassword Master password. Should be specified if configuration is protected by master password. Use -MasterPassword (ConvertTo-SecureString -string "Your_Password" -AsPlainText -Force) .EXAMPLE Remove-MBSBackupPlan -Name "File backup plan" Removes backup plan with name "File backup plan" .EXAMPLE Remove-MBSBackupPlan -id d39325ee-d54a-41e2-95d5-9bc476c7881d Removes backup plan with ID d39325ee-d54a-41e2-95d5-9bc476c7881d .INPUTS System.Management.Automation.PSCustomObject .OUTPUTS None .NOTES Author: Ivan Skorin .LINK https://kb.msp360.com/managed-backup-service/powershell-module/cmdlets/backup-agent/remove-mbsbackupplan/ #> [CmdletBinding()] param ( # Parameter - backup plan name [Parameter(Mandatory=$true, HelpMessage="Specify Backup plan name", ParameterSetName='Name')] [String] $Name, # Parameter - backup plan ID [Parameter(Mandatory=$true, HelpMessage="Specify Backup plan ID", ParameterSetName='ID', ValueFromPipelineByPropertyName)] [String] $ID, # Parameter - Master password [Parameter(Mandatory=$false, HelpMessage="Specify Master password. Use -MasterPassword (ConvertTo-SecureString -string ""Your_Password"" -AsPlainText -Force)")] [SecureString] $MasterPassword ) begin { if (-not($CBB = Get-MBSAgent)) { Break } try { if ((Get-MBSAgentSetting -ErrorAction SilentlyContinue).MasterPassword -ne "" -and (Get-MBSAgentSetting -ErrorAction SilentlyContinue).MasterPassword -ne $null -and -not $MasterPassword) { $MasterPassword = Read-Host Master Password -AsSecureString } } catch { } } process { if ($Name) { $Arguments = "deleteBackupPlan -n $Name" } else { $Arguments = "deleteBackupPlan -ID $ID" } if ($MasterPassword) { $Arguments += " -mp """+([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($MasterPassword)))+"""" } $Arguments += " -output short" Write-Verbose -message "Arguments: $Arguments" Start-Process -FilePath $CBB.CBBCLIPath -ArgumentList $Arguments -Wait -NoNewWindow } end { } } |