StorageDsc icon indicating copy to clipboard operation
StorageDsc copied to clipboard

Disk (MSFT_Disk): Opens Format Window

Open paraknell opened this issue 6 years ago • 5 comments

Disk (MSFT_Disk): Opens Format Window - and not in the CLI

Details

When Running the above script the verbose output returns no error messages and finishes cleanly however the "Formatting Disk (E:)" window is opened upon "completion" of the other operations. This forces you to still select formatting options through the GUI instead of remain on the CLI

If you run the below cmdlets it all runs within the CLI.

Get-Partition -DriveLetter 'C' | Resize-Partition -Size 32GB
New-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter 'E'
Format-Volume -DriveLetter 'E' -FileSystem NTFS -NewFileSystemLabel 'Data' -Full -Force

Verbose Output

Clean output no errors.

VERBOSE: [WIN-768UBAPULEL]: LCM:  [ End    Set      ]  [[Disk]EVolume]  in 3.8290 seconds.
VERBOSE: [WIN-768UBAPULEL]: LCM:  [ End    Resource ]  [[Disk]EVolume]
VERBOSE: [WIN-768UBAPULEL]: LCM:  [ End    Set      ]
VERBOSE: [WIN-768UBAPULEL]: LCM:  [ End    Set      ]    in  3.9380 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 3.985 seconds

Suggested solution to the issue

Adding something like this to the "Default NTFS option"

$volParams = @{
            FileSystem = $FSFormat
            Confirm    = $false
            Force = $true
            Full = $true
}

or this...

if ($FSFull)
{
    # Set the File System label on the new volume
    $volParams["Full"] = $Full
} # if
if ($FSForce)
{
    # Set the File System label on the new volume
    $volParams["FSForce"] = $FSForce
} # if

The DSC configuration that is used to reproduce the issue (as detailed as possible)

configuration buildFileServer
{
    Import-DSCResource -ModuleName StorageDsc

    Node localhost
    {
        Disk EVolume
        {
             DiskId = 0
             DriveLetter = 'E'
             FSLabel = 'Data'
        }

    }
}
buildFileServer

Set-DSCLocalConfigurationManager -Path .\buildFileServer –Verbose
Start-DscConfiguration -Wait -Force -Path .\buildFileServer -Verbose

If I look at the source code it shows:

if ($volume.FileSystem -eq '')
    {
        # The volume is not formatted
        $volParams = @{
            FileSystem = $FSFormat
            Confirm    = $false
        }

        if ($FSLabel)
        {
            # Set the File System label on the new volume
            $volParams["NewFileSystemLabel"] = $FSLabel
        } # if

        if ($AllocationUnitSize)
        {
            # Set the Allocation Unit Size on the new volume
            $volParams["AllocationUnitSize"] = $AllocationUnitSize
        } # if

        Write-Verbose -Message ( @(
                "$($MyInvocation.MyCommand): "
                $($localizedData.FormattingVolumeMessage -f $volParams.FileSystem)
            ) -join '' )

        # Format the volume
        $volume = $partition | Format-Volume @VolParams
}

So it should return soimething like this if we "break out" the params from @volparams $volume = $partition | Format-Volume -NewFileSystemLabel 'Data' -FileSystem NTFS

But it does not have the -Force or -Full params, which I believe are the options that enforce the process to remain within the CLI

The operating system the target node is running

OsName : Microsoft Windows Server 2016 Datacenter OsOperatingSystemSKU : DatacenterServerEdition WindowsBuildLabEx : 14393.0.amd64fre.rs1_release.160715-1616 OsLanguage : en-US OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

PSVersion: 5.1.14393.0 PSEdition: Desktop PSCompatibleVersions: {1.0, 2.0, 3.0, 4.0...} BuildVersion: 10.0.14393.0 CLRVersion: 4.0.30319.42000 WSManStackVersion: 3.0 PSRemotingProtocolVersion: 2.3 SerializationVersion: 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

Master

paraknell avatar Sep 14 '18 16:09 paraknell

Looks like this was a similar issue to: #148 And I also tested with:

Get-Partition -DriveLetter 'C' | Resize-Partition -Size 32GB
New-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter 'E'
Format-Volume -DriveLetter 'E' -FileSystem NTFS -NewFileSystemLabel 'Data' -Full

This will still bring up a prompt but allow the actual progress to be "tracked" within the CLI

paraknell avatar Sep 14 '18 17:09 paraknell

I have noticed this during integration tests and should be resolved if possible - although it doesn't seem to cause a failure. It should be easy enough to fix using your suggested code. I've got one PR going through at the moment so I'll include your code after that (unless you want to submit a PR?) .

PlagueHO avatar Sep 14 '18 22:09 PlagueHO

(For the PR) - Whatever works easiest for you :)

I ran some other tests and noticed that if you set it with the -Force parameter:

Format-Volume -DriveLetter 'E' -FileSystem NTFS -NewFileSystemLabel 'Data' -Full -Force

it will still show you a pop up stating the disk needs to be formatted. I even got it to state there was an error trying to format the drive and I didn't have the privileges to run that command, even though you can see it still running in the background with the write-progress showing completed successfully and also running it under an Admin account so it shouldn't be throwing a permissions issue.

The drive seems fine afterwards as well. Not sure if its a format-volume quirk or something else. I can post more information on monday, if you need it.

paraknell avatar Sep 16 '18 04:09 paraknell

Using Format-Volume with Full will actually write to every byte on the disk, and is not recommended when using thin provisioning. So using Full says that it should not use quick-format.

The GUI that pops up, isn't that just the GUI is to quick to find the disk will it still isn't reported as formatted? Isn't it a GUI "bug" and not a problem with running the cmdlets? 🤔

johlju avatar Sep 17 '18 09:09 johlju

I am currently using "Thick" provisioning for my VM's so I think -Full is the better option in the long run, I could definitely be wrong though... :)

But I'm betting to help those who do not use "Thick" provisioning there should be the option to turn it "on/off"

Disk EVolume
{
     Full = $true
}

You can add in the -Confirm parameter and it should suppress the gui window when you set it to false -Confirm:$false. Still testing as it seems it may not work in conjunction with the -Force parameter. But I'll update on that once I get more information.

UPDATES: If you run the cmdlets in quick succession the File I/O system doesn't have enough time to recognize the new partition has been created.

Get-Partition -DriveLetter 'C' | Resize-Partition -Size 32GB
New-Partition -DiskNumber 0 -UseMaximumSize -DriveLetter 'E'
Get-Partition -DriveLetter 'E' | Format-Volume -FileSystem NTFS -NewFileSystemLabel 'Data' -Force -Confirm:$false

If you add in a sleep 1 call then it will have enough time to run the New-Partition cmdlet successfully

Get-Partition -DriveLetter 'C' | Resize-Partition -Size 32GB
New-Partition -DiskNumber 0 -UseMaximumSize -DriveLetter 'E'
Sleep 1
Get-Partition -DriveLetter 'E' | Format-Volume -FileSystem NTFS -NewFileSystemLabel 'Data' -Force -Confirm:$false

This also seems to handle it correctly as well:

Get-Partition -DriveLetter 'C' | Resize-Partition -Size 32GB
New-Partition -DiskNumber 0 -UseMaximumSize -DriveLetter 'E'
$Edrive = Get-Partition -DriveLetter 'E'
Format-Volume -DriveLetter $Edrive.DriveLetter -FileSystem NTFS -NewFileSystemLabel 'Data' -Force -Confirm:$false

paraknell avatar Sep 17 '18 13:09 paraknell