Other Guides

MSP360 Products

MSP360 Managed Backup Service: Deleting Backup Files with PowerShell

The amount of data that companies back up is usually large, and this might result in higher payments for storage space. Thus, it is worth deleting unnecessary backups with all their files and folders. The process of manually removing everything from the storage might take a while but, at MSP360, we have a solution that can help. With the MSP360 Managed Backup Service PowerShell module, you’ll delete the files that you no longer need with just a few scripts.

The module was developed by our specialists as a powerful addition to the MSP360 Managed Backup Service. Our PowerShell module allows the automation of many tasks that might take too long if done manually. File deletion is one example.
Please note: if several backup plans share some files and/or folders, this data will be deleted from all plans. You won’t be able to restore it afterward, so be careful.
In the guide below, we’ll cover two topics: how to delete all the files from a file-level backup plan, and how to remove stale files that no longer exist in a file-level plan.

Installing the Managed Backup Service PowerShell Module

To install the module on your machine, run PowerShell console with administrator’s rights and then run this short script (it works for PowerShell 3.0 and above):

iex ((New-Object System.Net.WebClient).DownloadString('https://git.io/JUSAA')+'Install-MSP360Module')

If you get a message that the module can’t be installed because of execution policy restrictions, use this script:

Set-ExecutionPolicy RemoteSigned

Then, start the installation once again. Everything should be all right now.

How to Delete All the Files from a Backup Plan with the PowerShell Module

To delete files from a backup plan, you’ll need to know the name of this plan. If you remember its name, you can skip this step. Otherwise, use the cmdlet below to get the names of all your file-level plans across all storages.

  New call-to-action

Get-MBSBackupPlan -StorageType All -PlanType File-Level

Getting backup plan name using MSP 360 Managed Backup Service

Now, run the next script. It works as follows:

1. Locates a backup plan with the specified name.

2. Identifies an item as a file or a folder.

3. Removes it from the storage.

As a result, all files and folders get removed from the storage one by one.

$Plan = Get-MBSBackupPlan -PlanType File-Level | Where-Object Name -eq "Backup Plan Name"   

$Plan.Items.PlanItem.Path | ForEach-Object -Process {                                       

    $Options = @{StorageAccount = (Get-MBSStorageAccount -ID $Plan.ConnectionID)}



    }else {



    Remove-MBSBackup @Options                                                               


Deleting backup files one by one with MSP 360 Managed Backup Service

After this, you can run the backup plan to save new data to the storage or delete the plan if it is no longer needed using this script:

Remove-MBSPlan -Name "File backup plan", where “File backup plan” is the name of your plan.

How to Delete Files that Have Become Stale from a Backup Plan

If you change your backup plans from time to time, there might exist some files and folders that are no longer included in any plan. This data becomes stale and, in most cases, is not needed. However, it remains in storage, consuming space. With our PowerShell module, you can check what files and folders have been excluded from your backup plans and delete the data if you don’t need it anymore.

Use this cmdlet:


        [-StorageAccount] <StorageAccount>

        [[-MasterPassword] <SecureString>]


It revises the storage that you specify, compares the data in it with the data contained in backup plans, and if some files and folders are not bound to any plan, they are removed, unless you use the -WhatIf parameter. Adding this parameter shows what data is going to be deleted without executing the deletion. The script below just checks for such data in the storage called AWS:

Remove-MBSStaleBackup -StorageAccount (Get-MBSStorageAccount -Name "AWS") -WhatIf

And this script deletes such data, freeing space in this storage:

Remove-MBSStaleBackup -StorageAccount (Get-MBSStorageAccount -Name "AWS")

To delete files and folders that are unused in the backup plans from all the storages where you have set a master password in the backup agent, utilize this script:

C:\> Get-MBSStorageAccount | Remove-MBSStaleBackup -MasterPassword (ConvertTo-SecureString -string "Your_Password" -AsPlainText -Force)

“Your_Password” is the master password you have set for the storages.


When you have many backup plans and change them from time to time, some data might become unnecessary and there’s no need to pay to keep it. In this case, it is worth deleting it, saving both space in storage and your money. Manual deletion means that you’ll need to visit all the storage accounts and look for unused files and folders by yourself. Our PowerShell module makes this process really fast, so you can get rid of this data with just a few commands.

If you have any remaining questions, please contact our pre-sales team.

MSP360 Managed Backup. Simple. Reliable.
Powerful cross-platform backup and disaster recovery that leverages the public cloud to enable a comprehensive data protection strategy.
New call-to-action
MBS CTA image