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: Cannot convert System.UInt64 #210

Closed AussieDavo closed 4 years ago

AussieDavo commented 5 years ago

Details of the scenario you tried and the problem that is occurring

Error when running Test-TargetResource: Cannot convert the \"System.Object[]\" value of type \"System.Object[]\" to type \"System.UInt64\".

I have attempted deleting the partition and letting DSC recreate, which it does successfully but then fails again on the next Test-TargetResource.

I had some success after changing the VMware SCSI controller from "LSI Logic SAS" to "VMware Paravirtual" but after the next DSC run the error returned.

Verbose logs showing the problem

VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[OpticalDiskDriveLetter]SetCDRomDriveLetter]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[OpticalDiskDriveLetter]SetCDRomDriveLetter]
VERBOSE: [Server01]:                            [[OpticalDiskDriveLetter]SetCDRomDriveLetter]
Get-OpticalDiskDriveLetter: Using Get-CimInstance to get the drive letter of optical disk 1 in the system.
VERBOSE: [Server01]:                            [[OpticalDiskDriveLetter]SetCDRomDriveLetter] Perform operation
'Enumerate CimInstances' with following parameters, ''namespaceName' = root\cimv2,'className' = Win32_CDROMDrive'.
VERBOSE: [Server01]:                            [[OpticalDiskDriveLetter]SetCDRomDriveLetter] Operation 'Enumerate
CimInstances' complete.
VERBOSE: [Server01]:                            [[OpticalDiskDriveLetter]SetCDRomDriveLetter] Test-TargetResource: The
 optical disk 1 is assigned the drive letter 'E:' which is correct. Change not required.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[OpticalDiskDriveLetter]SetCDRomDriveLetter]  in 0.1200 seconds.
VERBOSE: [Server01]: LCM:  [ Skip   Set      ]  [[OpticalDiskDriveLetter]SetCDRomDriveLetter]
VERBOSE: [Server01]: LCM:  [ End    Resource ]  [[OpticalDiskDriveLetter]SetCDRomDriveLetter]
VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[WaitForDisk]WaitForDataDisk]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[WaitForDisk]WaitForDataDisk]
VERBOSE: [Server01]:                            [[WaitForDisk]WaitForDataDisk] Test-TargetResource: Checking for disk
with Number '1'.
VERBOSE: [Server01]:                            [[WaitForDisk]WaitForDataDisk] Test-TargetResource: Found disk with
Number '1' named 'VMware Virtual disk'.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[WaitForDisk]WaitForDataDisk]  in 0.9160 seconds.
VERBOSE: [Server01]: LCM:  [ Skip   Set      ]  [[WaitForDisk]WaitForDataDisk]
VERBOSE: [Server01]: LCM:  [ End    Resource ]  [[WaitForDisk]WaitForDataDisk]
VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[WaitForDisk]WaitForIISDisk]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[WaitForDisk]WaitForIISDisk]
VERBOSE: [Server01]:                            [[WaitForDisk]WaitForIISDisk] Test-TargetResource: Checking for disk
with Number '2'.
VERBOSE: [Server01]:                            [[WaitForDisk]WaitForIISDisk] Test-TargetResource: Found disk with
Number '2' named 'VMware Virtual disk'.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[WaitForDisk]WaitForIISDisk]  in 0.0380 seconds.
VERBOSE: [Server01]: LCM:  [ Skip   Set      ]  [[WaitForDisk]WaitForIISDisk]
VERBOSE: [Server01]: LCM:  [ End    Resource ]  [[WaitForDisk]WaitForIISDisk]
VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[WaitForDisk]WaitForQueueDisk]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[WaitForDisk]WaitForQueueDisk]
VERBOSE: [Server01]:                            [[WaitForDisk]WaitForQueueDisk] Test-TargetResource: Checking for disk
 with Number '3'.
VERBOSE: [Server01]:                            [[WaitForDisk]WaitForQueueDisk] Test-TargetResource: Found disk with
Number '3' named 'VMware Virtual disk'.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[WaitForDisk]WaitForQueueDisk]  in 0.0390 seconds.
VERBOSE: [Server01]: LCM:  [ Skip   Set      ]  [[WaitForDisk]WaitForQueueDisk]
VERBOSE: [Server01]: LCM:  [ End    Resource ]  [[WaitForDisk]WaitForQueueDisk]
VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[WaitForDisk]WaitForTransportDisk]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[WaitForDisk]WaitForTransportDisk]
VERBOSE: [Server01]:                            [[WaitForDisk]WaitForTransportDisk] Test-TargetResource: Checking for
disk with Number '4'.
VERBOSE: [Server01]:                            [[WaitForDisk]WaitForTransportDisk] Test-TargetResource: Found disk
with Number '4' named 'VMware Virtual disk'.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[WaitForDisk]WaitForTransportDisk]  in 0.0400 seconds.
VERBOSE: [Server01]: LCM:  [ Skip   Set      ]  [[WaitForDisk]WaitForTransportDisk]
VERBOSE: [Server01]: LCM:  [ End    Resource ]  [[WaitForDisk]WaitForTransportDisk]
VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[Disk]FormatQueueDisk]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[Disk]FormatQueueDisk]
VERBOSE: [Server01]:                            [[Disk]FormatQueueDisk] Test-TargetResource: Testing disk with Number
'3' status for drive letter 'Q'.
VERBOSE: [Server01]:                            [[Disk]FormatQueueDisk] Test-TargetResource: Checking if disk with
Number '3' is initialized.
Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.UInt64".
    + CategoryInfo          : InvalidArgument: (:) [], CimException
    + FullyQualifiedErrorId : ConvertToFinalInvalidCastException
    + PSComputerName        : localhost

VERBOSE: [Server01]:                            [[Disk]FormatQueueDisk] Perform operation 'Query CimInstances' with
following parameters, ''queryExpression' = SELECT BlockSize from Win32_Volume WHERE DriveLetter = 'Q:','queryDialect' =
 WQL,'namespaceName' = root\cimv2'.
VERBOSE: [Server01]:                            [[Disk]FormatQueueDisk] Operation 'Query CimInstances' complete.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[Disk]FormatQueueDisk]  in 4.6510 seconds.
The PowerShell DSC resource '[Disk]FormatQueueDisk' with SourceInfo '::75::9::Disk' threw one or more non-terminating
errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called
Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[Disk]FormatDataDisk]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[Disk]FormatDataDisk]
VERBOSE: [Server01]:                            [[Disk]FormatDataDisk] Test-TargetResource: Testing disk with Number
'1' status for drive letter 'D'.
VERBOSE: [Server01]:                            [[Disk]FormatDataDisk] Test-TargetResource: Checking if disk with
Number '1' is initialized.
Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.UInt64".
    + CategoryInfo          : InvalidArgument: (:) [], CimException
    + FullyQualifiedErrorId : ConvertToFinalInvalidCastException
    + PSComputerName        : localhost

VERBOSE: [Server01]:                            [[Disk]FormatDataDisk] Perform operation 'Query CimInstances' with
following parameters, ''queryExpression' = SELECT BlockSize from Win32_Volume WHERE DriveLetter = 'D:','queryDialect' =
 WQL,'namespaceName' = root\cimv2'.
VERBOSE: [Server01]:                            [[Disk]FormatDataDisk] Operation 'Query CimInstances' complete.
VERBOSE: [Server01]:                            [[Disk]FormatDataDisk] Test-TargetResource: Volume assigned to drive D
 has allocation unit size 0 KB does not match expected allocation unit size 64 KB.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[Disk]FormatDataDisk]  in 4.7300 seconds.
The PowerShell DSC resource '[Disk]FormatDataDisk' with SourceInfo '::86::9::Disk' threw one or more non-terminating
errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called
Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[Disk]FormatIISDisk]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[Disk]FormatIISDisk]
VERBOSE: [Server01]:                            [[Disk]FormatIISDisk] Test-TargetResource: Testing disk with Number
'2' status for drive letter 'I'.
VERBOSE: [Server01]:                            [[Disk]FormatIISDisk] Test-TargetResource: Checking if disk with
Number '2' is initialized.
Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.UInt64".
    + CategoryInfo          : InvalidArgument: (:) [], CimException
    + FullyQualifiedErrorId : ConvertToFinalInvalidCastException
    + PSComputerName        : localhost

VERBOSE: [Server01]:                            [[Disk]FormatIISDisk] Perform operation 'Query CimInstances' with
following parameters, ''queryExpression' = SELECT BlockSize from Win32_Volume WHERE DriveLetter = 'I:','queryDialect' =
 WQL,'namespaceName' = root\cimv2'.
VERBOSE: [Server01]:                            [[Disk]FormatIISDisk] Operation 'Query CimInstances' complete.
VERBOSE: [Server01]:                            [[Disk]FormatIISDisk] Test-TargetResource: Volume assigned to drive I
has allocation unit size 0 KB does not match expected allocation unit size 64 KB.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[Disk]FormatIISDisk]  in 3.5170 seconds.
The PowerShell DSC resource '[Disk]FormatIISDisk' with SourceInfo '::95::9::Disk' threw one or more non-terminating
errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called
Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

VERBOSE: [Server01]: LCM:  [ Start  Resource ]  [[Disk]FormatTransportDisk]
VERBOSE: [Server01]: LCM:  [ Start  Test     ]  [[Disk]FormatTransportDisk]
VERBOSE: [Server01]:                            [[Disk]FormatTransportDisk] Test-TargetResource: Testing disk with
Number '4' status for drive letter 'T'.
VERBOSE: [Server01]:                            [[Disk]FormatTransportDisk] Test-TargetResource: Checking if disk with
 Number '4' is initialized.
Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.UInt64".
    + CategoryInfo          : InvalidArgument: (:) [], CimException
    + FullyQualifiedErrorId : ConvertToFinalInvalidCastException
    + PSComputerName        : localhost

VERBOSE: [Server01]:                            [[Disk]FormatTransportDisk] Perform operation 'Query CimInstances'
with following parameters, ''queryExpression' = SELECT BlockSize from Win32_Volume WHERE DriveLetter =
'T:','queryDialect' = WQL,'namespaceName' = root\cimv2'.
VERBOSE: [Server01]:                            [[Disk]FormatTransportDisk] Operation 'Query CimInstances' complete.
VERBOSE: [Server01]: LCM:  [ End    Test     ]  [[Disk]FormatTransportDisk]  in 3.4870 seconds.
The PowerShell DSC resource '[Disk]FormatTransportDisk' with SourceInfo '::104::9::Disk' threw one or more
non-terminating errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel
called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

Suggested solution to the issue

I have a feeling it has something to do with the disk "size" value not being able to convert to UInt64 however I have no idea how to fix it.

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

configuration Disks2016 {
    Import-DscResource -ModuleName storagedsc -ModuleVersion '4.7.0.0'
    Import-DscResource -ModuleName ComputerManagementDsc -ModuleVersion '6.4.0.0'
    Import-DscResource -ModuleName PSDscResources -ModuleVersion '2.10.0.0'

    Node $allnodes.NodeName {

            OpticalDiskDriveLetter 'SetCDRomDriveLetter' {
                DiskId      = 1
                DriveLetter = 'E'
            }

            WaitForDisk "WaitForDataDisk" {
                DiskId = 1 
                DependsOn = '[OpticalDiskDriveLetter]SetCDRomDriveLetter'  
            }
            WaitForDisk "WaitForIISDisk" {
                DiskId = 2   
            }
            WaitForDisk "WaitForQueueDisk" {
                DiskId = 3   
            }
            WaitForDisk "WaitForTransportDisk" {
                DiskId = 4   
            }

            Disk "FormatQueueDisk" {
                DiskId = 3
                DriveLetter = "Q"
                FSLabel = "Queue"
                AllocationUnitSize = 64KB
                DependsOn = '[WaitForDisk]WaitForQueueDisk'
                PartitionStyle = "MBR"
            }

            Disk "FormatDataDisk" {
                DiskId = 1
                DriveLetter = "D"
                FSLabel = "Data"
                AllocationUnitSize = 64KB
                DependsOn = '[WaitForDisk]WaitForDataDisk'
                PartitionStyle = "MBR"
            }
            Disk "FormatIISDisk" {
                DiskId = 2
                DriveLetter = "I"
                FSLabel = "IIS"
                AllocationUnitSize = 64KB
                DependsOn = '[WaitForDisk]WaitForIISDisk'
                PartitionStyle = "MBR"
            }
            Disk "FormatTransportDisk" {
                DiskId = 4
                DriveLetter = "T"
                FSLabel = "Transport"
                AllocationUnitSize = 64KB
                DependsOn = '[WaitForDisk]WaitForTransportDisk'
                PartitionStyle = 'MBR'
            }
    }
}

The operating system the target node is running

OsName : Microsoft Windows Server 2016 Datacenter OsOperatingSystemSKU : DatacenterServerEdition OsArchitecture : 64-bit WindowsBuildLabEx : 14393.3085.amd64fre.rs1_release.190703-1816 OsLanguage : en-US OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

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

Version of the DSC module that was used

Master 4.7.0.0

PlagueHO commented 5 years ago

Hi @AussieDavo - I'm trying to track down where this error is occurring and my best guess is it is hitting this line: https://github.com/PowerShell/StorageDsc/blob/dev/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1#L810

And possibly has returned more than one partition (not sure how though).

What is returned if you execute:

Get-Partition -DriveLetter 'Q'

And:

 Get-Partition -DriveLetter 'Q' | Get-PartitionSupportedSize | Format-List *

On the node?

AussieDavo commented 5 years ago

Hi @PlagueHO - I have attempted executing the above and seem to get multiple partition results for Q however there is definitely only one partition on that disk:

PS C:\Users\user1> Get-Partition -DriveLetter 'Q'

   DiskPath: \\?\Disk{6be45e1f-c754-1348-8c6d-25a145b5e31f}

PartitionNumber  DriveLetter Offset                                        Size Type
---------------  ----------- ------                                        ---- ----
1                Q           1048576                                      25 GB IFS

   DiskPath: \\?\Disk{b7043479-9007-9c04-f7f0-36e11f645cbc}

PartitionNumber  DriveLetter Offset                                        Size Type
---------------  ----------- ------                                        ---- ----
1                Q           1048576                                      25 GB IFS

PS C:\Users\user1> Get-Partition -DriveLetter 'Q' | Get-PartitionSupportedSize | Format-List *

SizeMin : 3273654272
SizeMax : 26841448448

SizeMin : 3273654272
SizeMax : 26841448448

PS C:\Users\user1>

Q

It is the same for every other disk with the issue.

This seems to be leading more to being a VMware related issue and the way the disk is being presented to the Virtual machine.

I also did a bit more testing between "LSI Logic SAS" and "VMware Paravirtual" VMware SCSI controllers and came up with something interesting.

PowerShell results on a disk connected to a "LSI Logic SAS" SCSI controller:

PS C:\Users\user1> $disks = get-disk
PS C:\Users\user1> $supportedsize = $disks[0] | Get-Partition | Get-PartitionSupportedSize
PS C:\Users\user1> [System.UInt64]$Size = $supportedSize.SizeMax
Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.UInt64".
At line:1 char:1
+ [System.UInt64]$Size = $supportedSize.SizeMax
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (:) [], ArgumentTransformationMetadataException
    + FullyQualifiedErrorId : RuntimeException

PS C:\Users\user1>

PowerShell results on a disk connected to a "VMware Paravirtual" SCSI controller:

PS C:\Users\user1> $disks = get-disk
PS C:\Users\user1> $supportedsize = $disks[1] | Get-Partition | Get-PartitionSupportedSize
PS C:\Users\user1> [System.UInt64]$Size = $supportedSize.SizeMax
PS C:\Users\user1> $size
107372085248
PS C:\Users\user1>
PlagueHO commented 5 years ago

Thanks for that detailed info @AussieDavo .

It is strange that the partition shows up twice, but on two different disks (I'm assuming there is just one disk that appears twice in the disk subsystem). I'm thinking that we could detect and handle this situation by always selecting the first disk that matches. We would definitely need to make sure that this was deterministic and always selected the same disk.

Anyone else have any other info or ideas around why this is occurring?

aultt commented 4 years ago

@PlagueHO and @AussieDavo making the following change to the Test-TargetResource of MSFTDSC_Disk corrects the issue:
$partition = Get-Partition -DriveLetter $DriveLetter -ErrorAction SilentlyContinue | select-object -First 1

PlagueHO commented 4 years ago

Thanks @aultt - That does sound like a possibility. The assumption we made was that it shouldn't have been possible to have two partitions with the same drive letter assigned, but this might not be correct. I'll add this and release a preview version and see if it resolves the issue.

aultt commented 4 years ago

@PlagueHO sounds good I have tested it on my side with Windows2019 and it resolved the issue.

PlagueHO commented 4 years ago

@aultt - thank you for checking that and submitting the solution. I've updated the resource and it has no problems and all tests pass. I just need to add some unit tests to cover this and then I'll submit the PR.

PlagueHO commented 4 years ago

Hi @aultt, @AussieDavo - this has been deployed to the PSGallery as a preview version: https://www.powershellgallery.com/packages/StorageDsc/5.0.1-preview0003

I'll aim to release the full version in a week.

mmundy1 commented 3 years ago

I know this is a closed issue, but wanted to call out 1 more error case that causes this error even in 5.0.1. When you have increased disks in an underlying VM (VMWare in this case but probably a general scenario), but not done a rescan, the 'Cannot convert the "System.Object[]" value' occurs.

Doing a '"rescan" | diskpart' THEN running the DSC works

hervedupre commented 3 years ago

None of the "rescan" or "select-object -first 1" tricks worked for me (Win 2016 & 2019 under VmWare and Paravirtual scsi driver). I had to modify my code as : $Part | Resize-Partition -Size $sizemax[0] -ErrorAction SilentlyContinue -Verbose The [0] takes only the first size of the array of sizes, and if only 1 partition was got, it work also well. If fact, when you get twice the partition, it points to the same. It ends resizing twice the same partition, hence the -ErrorAction SilentlyContinue to avoid errors on the second pass.