diff --git a/CHANGELOG.md b/CHANGELOG.md index 45779e60..9899ac75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- DiskAccessPath: + - Added a Get-Partition to properly handle setting the NoDefaultDriveLetter + parameter - fixes [Issue #198](https://github.com/PowerShell/StorageDsc/pull/198). + ## 4.6.0.0 - Fix example publish to PowerShell Gallery by adding `gallery_api` diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index f963dd73..a361a589 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -518,22 +518,25 @@ function Set-TargetResource ) -join '' ) } # if + # Get the partitions on the disk + $partition = $disk | Get-Partition -ErrorAction SilentlyContinue + # Get the current partition state for NoDefaultDriveLetter $assignedPartition = $partition | Where-Object -Property AccessPaths -Contains -Value $AccessPath - if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $assignedPartition.NoDefaultDriveLetter, $NoDefaultDriveLetter)" - ) -join '' ) + if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $assignedPartition.NoDefaultDriveLetter, $NoDefaultDriveLetter)" + ) -join '' ) - # Setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot - Set-Partition -PartitionNumber $assignedPartition.PartitionNumber ` - -DiskNumber $disk.Number ` - -NoDefaultDriveLetter $NoDefaultDriveLetter - } # if + # Setting the partition property NoDefaultDriveLetter + Set-Partition -PartitionNumber $assignedPartition.PartitionNumber ` + -DiskNumber $disk.Number ` + -NoDefaultDriveLetter $NoDefaultDriveLetter + } # if } # Set-TargetResource <# diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 5c8267bf..bd0d24a1 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -651,7 +651,7 @@ try -ParameterFilter $script:parameterFilter_Disk0OfflineDiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 1 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1 @@ -724,7 +724,7 @@ try -ParameterFilter $script:parameterFilter_Disk0OfflineDiskIdUniqueId Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 1 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1 @@ -797,7 +797,7 @@ try -ParameterFilter $script:parameterFilter_Disk0OfflineDiskIdGuid Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 1 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1 @@ -869,7 +869,7 @@ try -ParameterFilter $script:parameterFilter_Disk0ReadonlyDiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 1 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1 @@ -943,7 +943,7 @@ try -ParameterFilter $script:parameterFilter_Disk0OfflineRawDiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 1 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 1 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1 @@ -1014,7 +1014,7 @@ try -ParameterFilter $script:parameterFilter_Disk0RawDiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 1 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 1 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1 @@ -1083,7 +1083,7 @@ try -ParameterFilter $script:parameterFilter_Disk0DiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 1 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1 @@ -1291,7 +1291,7 @@ try -ParameterFilter $script:parameterFilter_Disk0DiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 0 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0 @@ -1354,7 +1354,7 @@ try -ParameterFilter $script:parameterFilter_Disk0DiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 0 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0 @@ -1417,7 +1417,7 @@ try -ParameterFilter $script:parameterFilter_Disk0DiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 2 Assert-MockCalled -CommandName New-Partition -Exactly -Times 0 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0 @@ -1478,7 +1478,7 @@ try -ParameterFilter $script:parameterFilter_Disk0DiskIdNumber Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 Assert-MockCalled -CommandName New-Partition -Exactly -Times 0 Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0