ce -ResultClassName MSFT_StorageHealth -InputObject $storageSubSystem -CimSession $CimSession

            $arguments.Add("TargetObject", $InputObject)
        }
        else
        {
            if ($arguments["ValidationFlags"] -ne $null)
            {
                $errorObject = CreateErrorRecord -ErrorId "InvalidArgument" `
                                                 -ErrorMessage "The parameter 'ValidateVirtualDisksHealthy' is not supported in this subsystem. Invoke again without this parameter." `
                                                 -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidArgument) `
                                                 -Exception $null `
                                                 -TargetObject $null

                $psCmdlet.WriteError($errorObject)
                return
            }
        }

        # Would use a closure here, but jobs are run in their own session state.
        $block = {
            param($session, $asjob, $io, $arg, $ss, $sh)

            # Start-Job serializes/deserializes the CimSession,
            # which means it shows up here as having type Deserialized.CimSession.
            # Must recreate or cast the object in order to pass it to Get-CimInstance.
            if ($asjob)
            {
                $session = $session | New-CimSession
            }

            if ($ss.Model -eq "Clustered Windows Storage")
            {
                Invoke-CimMethod -MethodName "Maintenance" -Arguments $arg -InputObject $sh -CimSession $session | Out-Null
            }
            else
            {
                Invoke-CimMethod -MethodName "Maintenance" -Arguments $arg -InputObject $io -CimSession $session | Out-Null
            }
        }

        if ($asjob)
        {
            $p = $true
            Start-Job -ScriptBlock $block -ArgumentList @($CimSession, $p, $InputObject, $arguments, $storageSubSystem, $storageHealth)
        }
        else
        {
            if ($pscmdlet.ShouldProcess($info, $resources.warning, $info))
            {
                &$block $CimSession $p $InputObject $arguments $storageSubSystem $storageHealth
            }
        }
    }
}

function Disable-StorageMaintenanceMode
{
    [CmdletBinding()]
    Param
    (
        [Microsoft.Management.Infrastructure.CimInstance]
        [PSTypeName("Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_StorageFaultDomain")]
        [Parameter(
            Mandatory         = $true,
            ValueFromPipeline = $true,
            ParameterSetName  = "InputObject")]
        $InputObject,

        [string]
        $Model,

        [string]
        $Manufacturer,

        [Microsoft.Management.Infrastructure.CimSession]
        $CimSession,

        [Switch]
        $AsJob
    )

    Begin{}

    Process
    {
        $info = $resources.info
        $p = $null

        if (-not $CimSession)
        {
            $CimSession = New-CimSession
        }

        if ($InputObject.CimClass.CimClassName -ne "MSFT_PhysicalDisk" -and
            $InputObject.CimClass.CimClassName -ne "MSFT_StorageEnclosure" -and
            $InputObject.CimClass.CimClassName -ne "MSFT_StorageScaleUnit")
        {
            $errorObject = CreateErrorRecord -ErrorId "InvalidArgument" `
                                             -ErrorMessage "The input object must be a PhysicalDisk, StorageEnclosure or StorageScaleUnit" `
                                             -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidArgument) `
                                             -Exception $null `
                                             -TargetObject $null

            $psCmdlet.WriteError($errorObject)
            return
        }

        $arguments = @{}

        $arguments.Add("EnableMaintenanceMode", $false)

        if($InputObject.CimClass.CimClassName -ne "MSFT_PhysicalDisk")
        {
            if ($PSBoundParameters.ContainsKey("Model"))
            {
                $arguments.Add("Model", $Model)
            }

            if ($PSBoundParameters.ContainsKey("Manufacturer"))
            {
                $arguments.Add("Manufacturer", $Manufacturer)
            }
        }

        $storageSubSystem = $InputObject | Get-StorageSubSystem -CimSession $CimSession

        if ($storageSubSystem.Model -eq "Clustered Windows Storage")
        {
            $arguments.Add("TargetObject", $InputObject)

            $storageHealth = Get-CimAssociatedInstance -ResultClassName MSFT_StorageHealth -InputObject $storageSubSystem -CimSession $CimSession
        }

        # Would use a closure here, but jobs are run in their own session state.
        $block = {
            param($session, $asjob, $io, $arg, $ss, $sh)

            # Start-Job serializes/deserializes the CimSession,
            # which means it shows up here as having type Deserialized.CimSession.
            # Must recreate or cast the object in order to pass it to Get-CimInstance.
            if ($asjob)
            {
                $session = $session | New-CimSession
            }

            if ($ss.Model -eq "Clustered Windows Storage")
            {
                Invoke-CimMethod -MethodName "Maintenance" -Arguments $arg -InputObject $sh -CimSession $session | Out-Null
            }
            else
            {
                Invoke-CimMethod -MethodName "Maintenance" -Arguments $arg -InputObject $io -CimSession $session | Out-Null
            }
        }

        if ($asjob)
        {
            $p = $true
            Start-Job -ScriptBlock $block -ArgumentList @($CimSession, $p, $InputObject, $arguments, $storageSubSystem, $storageHealth)
        }
        else
        {
            if ($pscmdlet.ShouldProcess($info, $resources.warning, $info))
            {
                &$block $CimSession $p $InputObject $arguments $storageSubSystem $storageHealth
            }
        }
    }
}


function Get-StorageDiagnosticInfo
{
    [CmdletBinding()]
    Param
    (
        #### -------------------- Parameter sets -------------------------------------####

        [Microsoft.Management.Infrastructure.CimInstance]
        [PSTypeName("Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_StorageSubSystem")]
        [Parameter(
            ParameterSetName  = "ByStorageSubSystem",
            ValueFromPipeline = $true,
            Mandatory         = $true)]
        [ValidateNotNullOrEmpty()]
        $InputObject,

        [String]
        [Parameter(
            ParameterSetName  = "ByStorageSubSystemFriendlyName",
            Mandatory         = $true,
            Position          = 0)]
        [ValidateNotNullOrEmpty()]
        $StorageSubSystemFriendlyName,

        [String]
        [Parameter(
            ParameterSetName  = "ByStorageSubSystemName",
            Mandatory         = $true)]
        [ValidateNotNullOrEmpty()]
        $StorageSubSystemName,

        [String]
        [Parameter(
            ParameterSetName  = "ByStorageSubSystemUniqueId",
            Mandatory         = $true)]
        [ValidateNotNullOrEmpty()]
        [Alias("StorageSubSystemId")]
        $StorageSubSystemUniqueId,

        #### -------------------- Method parameters ----------------------------------####

        [String]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystem',
            Mandatory        = $true)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemFriendlyName',
            Mandatory        = $true)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemName',
            Mandatory        = $true)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemUniqueId',
            Mandatory        = $true)]
        [ValidateNotNullOrEmpty()]
        [Alias("Path")]
        $DestinationPath,

        [UInt32]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystem',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemFriendlyName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemUniqueId',
            Mandatory        = $false)]
        $TimeSpan,

        [String]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystem',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemFriendlyName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemUniqueId',
            Mandatory        = $false)]
        $ActivityId,

        [System.Management.Automation.SwitchParameter]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystem',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemFriendlyName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemUniqueId',
            Mandatory        = $false)]
        $ExcludeOperationalLog = $false,

        [System.Management.Automation.SwitchParameter]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystem',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemFriendlyName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemUniqueId',
            Mandatory        = $false)]
        $ExcludeDiagnosticLog = $false,

        [System.Management.Automation.SwitchParameter]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystem',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemFriendlyName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemName',
            Mandatory        = $false)]
        [Parameter(
            ParameterSetName = 'ByStorageSubSystemUniqueId',
            Mandatory        = $false)]
        $IncludeLiveDump = $false,

        #### -------------------- Powershell parameters ------------------------------####

        [Microsoft.Management.Infrastructure.CimSession]
        $CimSession,

        # Provided for compatibility with CDXML cmdlets, not actually used.
        [Int32]
        $ThrottleLimit,

        [Switch]
        $AsJob
    )

    Process
    {
        $info = $resources.info
        $p = $null

        if (-not $CimSession)
        {
            $CimSession = New-CimSession
        }

        if (-not $AsJob)
        {
            Write-Progress -Activity "Get-StorageDiagnosticInfo" -Id 0 -PercentComplete 0 -CurrentOperation "Validating parameters" -Status "0/2"
        }

        ## Gather the instance object

        switch ($psCmdlet.ParameterSetName)
        {
            "ByStorageSubSystem"             { $SubsystemInstance = $InputObject; break; }
            "ByStorageSubSystemFriendlyName" { $SubsystemInstance = Get-StorageSubsystem -FriendlyName $StorageSubSystemFriendlyName -CimSession $CimSession -ErrorAction Stop; break; }
            "ByStorageSubSystemName"         { $SubsystemInstance = Get-StorageSubsystem -Name $StorageSubSystemName -CimSession $CimSession -ErrorAction Stop; break; }
            "ByStorageSubSystemUniqueId"     { $SubsystemInstance = Get-StorageSubsystem -UniqueId $StorageSubSystemUniqueId -CimSession $CimSession -ErrorAction Stop; break; }
        }

        # Would use a closure here, but jobs are run in their own session state.
        $methodblock = {
            param($session, $asjob, $uniqueId, $arguments)

            # Start-Job serializes/deserializes the CimSession,
            # which means it shows up here as having type Deserialized.CimSession.
            # Must recreate or cast the object in order to pass it to Get-CimInstance.
            if ($asjob)
            {
                # We need to load the module or it fails with CMDLET Not Found
                import-module Storage\StorageSubSystem.cdxml

                $session = $session | New-CimSession
            }

            $parameters = @{}

            $parameters.Add("CimSession", $session )
            $parameters.Add("StorageSubSystemUniqueId", $uniqueId )
            $parameters.Add("DestinationPath", $arguments["DestinationPath"] )

            if ($arguments.ContainsKey("TimeSpan"))
            {
                $parameters.Add("TimeSpan", $arguments["TimeSpan"])
            }

            if ($arguments.ContainsKey("ActivityId"))
            {
                $parameters.Add("ActivityId", $arguments["ActivityId"])
            }

            if ($arguments.ContainsKey("ExcludeOperationalLog"))
            {
                $parameters.Add("ExcludeOperationalLog", $arguments["ExcludeOperationalLog"])
            }

            if ($arguments.ContainsKey("ExcludeDiagnosticLog"))
            {
                $parameters.Add("ExcludeDiagnosticLog", $arguments["ExcludeDiagnosticLog"])
            }

            if ($arguments.ContainsKey("IncludeLiveDump"))
            {
                $parameters.Add("IncludeLiveDump", $arguments["IncludeLiveDump"])
            }

            if (-not $asjob)
            {
                Write-Progress -Activity "Get-StorageDiagnosticInfo" -Id 0 -PercentComplete 10 -CurrentOperation "Gathering storage diagnostic logs" -Status "1/2"
            }

            Get-StorageDiagnosticInfoInternal @parameters

            if (-not $asjob)
            {
                Write-Progress -Activity "Get-StorageDiagnosticInfo" -Completed -Status "2/2"
            }
        }

        if ($asjob)
        {
            $p = $true

            Start-Job -Name GetDiagnosticInfo `
                      -ScriptBlock $methodblock `
                      -ArgumentList @($CimSession, $p, $SubsystemInstance.UniqueId, $PSBoundParameters)
        }
        else
        {
            &$methodblock $CimSession $p $SubsystemInstance.UniqueId $PSBoundParameters
        }
    }
}

function Remove-StorageHealthIntent
{
    [CmdletBinding(
        SupportsShouldProcess=$true,
        ConfirmImpact="High"
    )]
    Param
    (
        [Microsoft.Management.Infrastructure.CimInstance]
        [PSTypeName("Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_StorageObject")]
        [Parameter(
            Mandatory         = $true,
            ValueFromPipeline = $true,
            ParameterSetName  = "InputObject")]
         $InputObject,

        [Microsoft.Management.Infrastructure.CimSession]
        $CimSession,

        [Switch]
        $AsJob
    )

    Process
    {
        $info = $resources.info

        if (-not $CimSession)
        {
            $CimSession = New-CimSession -Verbose:$false
        }

        $arguments = @{}

        $storageSubSystem = $InputObject | Get-StorageSubSystem -CimSession $CimSession

        if ($storageSubSystem.Model -eq "Clustered Windows Storage")
        {
            $storageHealth = Get-CimAssociatedInstance -ResultClassName MSFT_StorageHealth -InputObject $storageSubSystem -CimSession $CimSession

            $arguments.Add("TargetObject", $InputObject)
        }
        else
        {
            $errorObject = CreateErrorRecord -ErrorId "InvalidSubsystem" `
                                             -ErrorMessage "This method is not supported for this subsystem." `
                                             -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidArgument) `
                                             -Exception $null `
                                             -TargetObject $null

            $psCmdlet.WriteError($errorObject)
            return
        }

        # Would use a closure here, but jobs are run in their own session state.
        $block = {
            param($session, $asjob, $io, $arg, $sh)

            # Start-Job serializes/deserializes the CimSession,
            # which means it shows up here as having type Deserialized.CimSession.
            # Must recreate or cast the object in order to pass it to Get-CimInstance.
            if ($asjob)
            {
                $session = $session | New-CimSession -Verbose:$false
            }

            Invoke-CimMethod -MethodName "RemoveIntent" -Arguments $arg -InputObject $sh -CimSession $session | Out-Null
        }

        if ($asjob)
        {
            Start-Job -ScriptBlock $block -ArgumentList @($CimSession, $true, $InputObject, $arguments, $storageHealth)
        }
        else
        {
            if ($pscmdlet.ShouldProcess($info, $resources.warning, $info))
            {
                &$block $CimSession $false $InputObject $arguments $storageHealth
            }
        }
    }
}

New-Alias Get-PhysicalDiskSNV Get-PhysicalDiskStorageNodeView
New-Alias Get-DiskSNV Get-DiskStorageNodeView
New-Alias Get-StorageEnclosureSNV Get-StorageEnclosureStorageNodeView

Export-ModuleMember -Alias * -Function *