diff --git a/CHANGELOG.md b/CHANGELOG.md index 45779e60..94c229fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## 4.7.0.0 + +- 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/DSCResources/MSFT_OpticalDiskDriveLetter/README.md b/DSCResources/MSFT_OpticalDiskDriveLetter/README.md index 9df3ce47..aba1f40d 100644 --- a/DSCResources/MSFT_OpticalDiskDriveLetter/README.md +++ b/DSCResources/MSFT_OpticalDiskDriveLetter/README.md @@ -29,8 +29,11 @@ With the Device ID, we look for the length of the string after the final backslash (crude, but appears to work so far). Example: - # DeviceID for a virtual drive in a Hyper-V VM - SCSI\CDROM&VEN_MSFT&PROD_VIRTUAL_DVD-ROM\**000006** - # DeviceID for a mounted ISO in a Hyper-V VM - SCSI\CDROM&VEN_MSFT&PROD_VIRTUAL_DVD-ROM\**2&1F4ADFFE&0&000002** +```powershell +# DeviceID for a virtual drive in a Hyper-V VM +"SCSI\CDROM&VEN_MSFT&PROD_VIRTUAL_DVD-ROM\**000006**" + +# DeviceID for a mounted ISO in a Hyper-V VM +"SCSI\CDROM&VEN_MSFT&PROD_VIRTUAL_DVD-ROM\**2&1F4ADFFE&0&000002**" +``` diff --git a/StorageDsc.psd1 b/StorageDsc.psd1 index 886a5096..91326055 100644 --- a/StorageDsc.psd1 +++ b/StorageDsc.psd1 @@ -3,7 +3,7 @@ # RootModule = '' # Version number of this module. - moduleVersion = '4.6.0.0' + moduleVersion = '4.7.0.0' # ID used to uniquely identify this module GUID = '00d73ca1-58b5-46b7-ac1a-5bfcf5814faf' @@ -102,23 +102,9 @@ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '- Fix example publish to PowerShell Gallery by adding `gallery_api` - environment variable to `AppVeyor.yml` - fixes [Issue 202](https://github.com/PowerShell/StorageDsc/issues/202). -- Added "DscResourcesToExport" to manifest to improve information in - PowerShell Gallery and removed wildcards from "FunctionsToExport", - "CmdletsToExport", "VariablesToExport" and "AliasesToExport" - fixes - [Issue 192](https://github.com/PowerShell/StorageDsc/issues/192). -- Clean up module manifest to correct Author and Company - fixes - [Issue 191](https://github.com/PowerShell/StorageDsc/issues/191). -- Correct unit tests for DiskAccessPath to test exact number of - mocks called - fixes [Issue 199](https://github.com/PowerShell/StorageDsc/issues/199). -- Disk: - - Added minimum timetowate of 3s after new-partition using the while loop. - The problem occurs when the partition is created and the format-volume - is attempted before the volume has completed. - There appears to be no property to determine if the partition is - sufficiently ready to format and it will often format as a raw volume when - the error occurs - fixes [Issue 85](https://github.com/PowerShell/StorageDsc/issues/85). + ReleaseNotes = '- DiskAccessPath: + - Added a Get-Partition to properly handle setting the NoDefaultDriveLetter + parameter - fixes [Issue 198](https://github.com/PowerShell/StorageDsc/pull/198). ' @@ -133,3 +119,4 @@ # DefaultCommandPrefix = '' } + 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