From 8ea6e863fc6b935da137b8a991cbbc27914977b4 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Mon, 4 Mar 2019 18:19:03 -0500 Subject: [PATCH 1/7] fixing get-partition to pull current state --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index f963dd73..c5407c9c 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -519,7 +519,7 @@ function Set-TargetResource } # if # Get the current partition state for NoDefaultDriveLetter - $assignedPartition = $partition | + $assignedPartition = Get-Partition -PartitionNumber $partition.PartitionNumber | Where-Object -Property AccessPaths -Contains -Value $AccessPath if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) From dba31ef0fb5f475b7667a822d7111ee2b74ba4c7 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 5 Mar 2019 07:53:37 -0500 Subject: [PATCH 2/7] changing logic to get partition state --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index c5407c9c..226c47a4 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -518,8 +518,11 @@ 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 = Get-Partition -PartitionNumber $partition.PartitionNumber | + $assignedPartition = $partition | Where-Object -Property AccessPaths -Contains -Value $AccessPath if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) From bd6e0b1351b212c4927ef0ab7a5442a58c565a29 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 5 Mar 2019 08:14:23 -0500 Subject: [PATCH 3/7] code review updates --- .../MSFT_DiskAccessPath.psm1 | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 226c47a4..a361a589 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -525,18 +525,18 @@ function Set-TargetResource $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 <# From e4092320328f1f218d4e6f463894c63c23db78e9 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 11 Apr 2019 15:18:29 -0400 Subject: [PATCH 4/7] get-partition called 2 times for nodefautldriveletter unit tests --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 From 9b8ef586ef87c97f1a56267b341783e3cd82de41 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Sat, 13 Apr 2019 08:57:36 -0400 Subject: [PATCH 5/7] update changelog for PR 198 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45779e60..12e677aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- DiskAccessPath: + - Added a get-partion 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` From cebcfd8a16af6f1efa734e805f6b2e1e8bfabdce Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Sat, 13 Apr 2019 18:56:13 -0400 Subject: [PATCH 6/7] update changelog for typo spelling --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12e677aa..d8c47115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased - DiskAccessPath: - - Added a get-partion to properly handle setting the NoDefaultDriveLetter + - 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 From 0a3e30ee37958b0d10b3581622d5c8f858b75f86 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Sat, 13 Apr 2019 18:59:14 -0400 Subject: [PATCH 7/7] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8c47115..9899ac75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - DiskAccessPath: - Added a Get-Partition to properly handle setting the NoDefaultDriveLetter - parameter - fixes [Issue #198](https://github.com/PowerShell/StorageDsc/pull/198) + parameter - fixes [Issue #198](https://github.com/PowerShell/StorageDsc/pull/198). ## 4.6.0.0