Public/Storage/Remove-VmsStorage.ps1

function Remove-VmsStorage {
    <#
    .SYNOPSIS
        Removes a Milestone XProtect recording server storage configuration and all of the child archive storages if present
    .DESCRIPTION
        If the specified storage is not marked as the default storage, and there are no devices configured to record to the
        storage, this function removes the storage configuration including any and all archive storages attached to the live
        drive represented by the storage configuration.
    .PARAMETER RecordingServer
        Specifies the RecordingServer object from which to look for matching storage configurations
    .PARAMETER Name
        Specifies the name of the existing storage configuration to look for on the specified recording server
    .PARAMETER Storage
        Specifies the Storage object to be removed
    .EXAMPLE
        PS C:\> Get-RecordingServer | Remove-VmsStorage -Name 'Old Storage Config'
        Removes the storage configuration named 'Old Storage Config' from all recording servers
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    param (
        [Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'ByName')]
        [VideoOS.Platform.ConfigurationItems.RecordingServer]
        $RecordingServer,

        [Parameter(Mandatory, ParameterSetName = 'ByName')]
        [ValidateNotNullOrEmpty()]
        [string]
        $Name,

        [Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'ByStorage')]
        [VideoOS.Platform.ConfigurationItems.Storage]
        $Storage
    )
    
    process {
        switch ($PSCmdlet.ParameterSetName) {
            'ByName' {
                foreach ($vmsStorage in $RecordingServer | Get-VmsStorage -Name $Name) {
                    $vmsStorage | Remove-VmsStorage
                }
            }

            'ByStorage' {
                $recorder = [VideoOS.Platform.ConfigurationItems.RecordingServer]::new((Get-ManagementServer).ServerId, $Storage.ParentItemPath)
                if ($PSCmdlet.ShouldProcess("Recording server $($recorder.Name)", "Delete $($Storage.Name) and all archives")) {
                    $folder = [VideoOS.Platform.ConfigurationItems.StorageFolder]::new((Get-ManagementServer).ServerId, $Storage.ParentPath)
                    [void]$folder.RemoveStorage($Storage.Path)
                }
            }
            Default {
                throw 'Unknown parameter set'
            }
        }
    }
}