dsccommunity / StorageDsc

DSC resource module is used to manage storage on Windows Servers.
https://dsccommunity.org
MIT License
69 stars 51 forks source link

Disk: Invalid Parameter error occurs with ReFS Volume on Windows Server 2019 #227

Open PlagueHO opened 4 years ago

PlagueHO commented 4 years ago

When using the Disk resource to create ReFS volumes on Windows Server 2019, an "Invalid Parameter" exception occurs when calling the Format-Volume cmdlet in the Set method.

This can be replicated outside of the DSC Resource with the following code:

function New-VDisk
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $True)]
        [String]
        $Path,

        [Parameter()]
        [Uint32]
        $SizeInMB,

        [Parameter()]
        [Switch]
        $Initialize
    )

    $tempScriptPath = Join-Path -Path $ENV:Temp -ChildPath 'DiskPartVdiskScript.txt'
    Write-Verbose -Message ('Creating DISKPART script {0}' -f $tempScriptPath)

    $diskPartScript = "CREATE VDISK FILE=`"$Path`" TYPE=EXPANDABLE MAXIMUM=$SizeInMB"

    if ($Initialize)
    {
        # The disk will be initialized with GPT (first blank line required because we're adding to existing string)
        $diskPartScript += @"

SELECT VDISK FILE=`"$Path`"
ATTACH VDISK
CONVERT GPT
DETACH VDISK
"@
    }

    Set-Content `
        -Path $tempScriptPath `
        -Value $diskPartScript `
        -Encoding Ascii
    $result = & DISKPART @('/s',$tempScriptPath)
    Write-Verbose -Message ($Result | Out-String)
    $null = Remove-Item -Path $tempScriptPath -Force
} # end function New-VDisk

$VHDPath = Join-Path -Path $ENV:Temp -ChildPath 'TestDisk.vhd'
$null = New-VDisk -Path $VHDPath -SizeInMB 1024
$null = Mount-DiskImage -ImagePath $VHDPath -StorageType VHD -NoDriveLetter
$diskImage = Get-DiskImage -ImagePath $VHDPath
$disk = Get-Disk -Number $diskImage.Number
$FSLabel = 'TestDisk'
$disk | Initialize-Disk -PartitionStyle GPT
$partition = $disk | New-Partition -UseMaximumSize

# Following line works on WS 2016, but not on WS 2019. 
$partition | Format-Volume -FileSystem ReFS

# Invalid Parameter occurs

$null = Dismount-DiskImage -ImagePath $VHDPath -StorageType VHD
$null = Remove-Item -Path $VHDPath -Force

The exception occurs: image

The error appears to be in the WMI subsystem.

This should be logged with the Window Server storage team. I'll try and find the appropriate method to log the issue.

In the mean time there are two things than should be done:

  1. Change the resource to display a warning message when ReFS is used with Windows Server 2019.
  2. Add a known issue in the README.MD
TaylorTWBrown commented 3 years ago

Still experiencing this issue.

PlagueHO commented 3 years ago

@TaylorTWBrown - does this occur outside DSC and which version of WS 2019 is this on?