Public/Disable-HPDCDiskCaching.ps1

Function Disable-HPDCDiskCaching {
    <#
        .SYNOPSIS
            Disable caching on the specified disk.
        .DESCRIPTION
            Disable caching on the specified disk.
        .PARAMETER DiskNumber
            Number of the disk to disable Disk Caching on.
        .INPUTS
            System.Int
        .OUTPUTS
            Returns 0 when successful. Otherwise, it returns an error code.
        .EXAMPLE
            Disable-HPDCDiskCaching -DiskNumber 1
 
            This will disable disk caching on disk number 1
        .LINK
            about_functions_advanced
        .LINK
            about_CommonParameters
        .LINK
            http://h10032.www1.hp.com/ctg/Manual/c06173592
    #>

    [CmdletBinding(
        SupportsShouldProcess = $true,
        ConfirmImpact = $true
    )]
    Param(
        [Parameter(Mandatory = $true)]
        [int]$DiskNumber
    )
    If ($null -ne $HpDC) {
        If ($PSCmdlet.ShouldProcess("DiskNumber: $DiskNumber", "Disable disk caching")) {
            $Ret = $HpDC.DisableCaching($DiskNumber)
            If ($Ret.ReturnValue -gt 0) {
                Throw "Caching NOT disabled on disk $DiskNumber - Error: $Ret.ReturnValue"
            } Else {
                Write-Output "Caching disabled on disk $DiskNumber"
                ForEach ($Item in $HPDCI) {
                    If ($Item.DiskNumber -eq $DiskNumber) {
                        Write-Warning "Caching set to $Item.CachingEnabled for disk $Item.DiskNumber on next boot"
                    }
                }
            }
        }
    }
}