Skip to content

Commit

Permalink
Merge pull request #187 from JoshuaJSwain/jswain_xdiskaccesspath_145
Browse files Browse the repository at this point in the history
diskaccesspath: fixes issue 145 drive letter assignment to mountpoint volumes
  • Loading branch information
PlagueHO authored Feb 20, 2019
2 parents f789b0f + 7575659 commit 6845338
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
## Unreleased

- Opt-in to Example publishing to PowerShell Gallery - fixes [Issue #186](https://github.com/PowerShell/StorageDsc/issues/186).
- DiskAccessPath:
- Updated the resource to not assign a drive letter by default when adding
a disk access path. Adding a Set-Partition -NoDefaultDriveLetter
$NoDefaultDriveLetter block defaulting to true.
When adding access paths the disks will no longer have
drive letters automatically assigned on next reboot which is the desired
behavior - Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145).

## 4.4.0.0

Expand Down
65 changes: 57 additions & 8 deletions DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ $localizedData = Get-LocalizedData `
.PARAMETER AccessPath
Specifies the access path folder to the assign the disk volume to
.PARAMETER NoDefaultDriveLetter
Prevents a default drive letter from being assigned to a newly created partition. Defaults to True.
.PARAMETER DiskId
Specifies the disk identifier for the disk to modify.
Expand Down Expand Up @@ -55,6 +58,10 @@ function Get-TargetResource
[System.String]
$AccessPath,

[Parameter()]
[System.Boolean]
$NoDefaultDriveLetter = $true,

[Parameter(Mandatory = $true)]
[System.String]
$DiskId,
Expand Down Expand Up @@ -115,13 +122,14 @@ function Get-TargetResource
-ErrorAction SilentlyContinue).BlockSize

$returnValue = @{
DiskId = $DiskId
DiskIdType = $DiskIdType
AccessPath = $AccessPath
Size = $assignedPartition.Size
FSLabel = $FSLabel
AllocationUnitSize = $blockSize
FSFormat = $fileSystem
DiskId = $DiskId
DiskIdType = $DiskIdType
AccessPath = $AccessPath
NoDefaultDriveLetter = $assignedPartition.NoDefaultDriveLetter
Size = $assignedPartition.Size
FSLabel = $FSLabel
AllocationUnitSize = $blockSize
FSFormat = $fileSystem
}
$returnValue
} # Get-TargetResource
Expand All @@ -133,6 +141,9 @@ function Get-TargetResource
.PARAMETER AccessPath
Specifies the access path folder to the assign the disk volume to
.PARAMETER NoDefaultDriveLetter
Prevents a default drive letter from being assigned to a newly created partition. Defaults to True.
.PARAMETER DiskId
Specifies the disk identifier for the disk to modify.
Expand Down Expand Up @@ -162,6 +173,10 @@ function Set-TargetResource
[System.String]
$AccessPath,

[Parameter()]
[System.Boolean]
$NoDefaultDriveLetter = $true,

[Parameter(Mandatory = $true)]
[System.String]
$DiskId,
Expand Down Expand Up @@ -409,7 +424,7 @@ function Set-TargetResource
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.PartitionAlreadyAssignedMessage -f `
$AccessPath, $partition.PartitionNumber)
$AccessPath, $assignedPartition.PartitionNumber)
) -join '' )

$assignAccessPath = $false
Expand Down Expand Up @@ -502,6 +517,23 @@ function Set-TargetResource
$($localizedData.SuccessfullyInitializedMessage -f $AccessPath)
) -join '' )
} # if

# 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 '' )

# 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
} # Set-TargetResource

<#
Expand All @@ -511,6 +543,9 @@ function Set-TargetResource
.PARAMETER AccessPath
Specifies the access path folder to the assign the disk volume to
.PARAMETER NoDefaultDriveLetter
Prevents a default drive letter from being assigned to a newly created partition. Defaults to True.
.PARAMETER DiskId
Specifies the disk identifier for the disk to modify.
Expand Down Expand Up @@ -539,6 +574,10 @@ function Test-TargetResource
[System.String]
$AccessPath,

[Parameter()]
[System.Boolean]
$NoDefaultDriveLetter = $true,

[Parameter(Mandatory = $true)]
[System.String]
$DiskId,
Expand Down Expand Up @@ -636,6 +675,16 @@ function Test-TargetResource
return $false
} # if

# Check if the partition NoDefaultDriveLetter parameter is correct
if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter)
{
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($localizedData.NoDefaultDriveLetterMismatchMessage -f $assignedPartition.NoDefaultDriveLetter, $NoDefaultDriveLetter)
) -join '' )
return $false
} # if

# Partition size was passed so check it
if ($Size)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class MSFT_DiskAccessPath : OMI_BaseResource
{
[Key, Description("Specifies the access path folder to the assign the disk volume to.")] String AccessPath;
[Write, Description("Specifies no automatic drive letter assignment to the partition: Defaults to True")] Boolean NoDefaultDriveLetter;
[Required, Description("Specifies the disk identifier for the disk to modify.")] String DiskId;
[Write, Description("Specifies the identifier type the DiskId contains. Defaults to Number."), ValueMap{"Number","UniqueId","Guid"}, Values{"Number","UniqueId","Guid"}] String DiskIdType;
[Write, Description("Specifies the size of new volume.")] Uint64 Size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
DiskReadOnlyMessage = Disk with {0} '{1}'is readonly.
DiskNotGPTMessage = Disk with {0} '{1}' is initialised with '{2}' partition style. GPT required.
AccessPathNotFoundMessage = A volume assigned to access path '{0}' was not found.
NoDefaultDriveLetterMismatchMessage = Partition default drive letter assigmemt parameter '{0}' does not match '{1}'.
SizeMismatchMessage = Partition assigned to access path '{0}' has size {1}, which does not match expected size {2}.
AllocationUnitSizeMismatchMessage = Volume assigned to access path '{0}' has allocation unit size {1} KB does not match expected allocation unit size {2} KB.
FileSystemFormatMismatch = Volume assigned to access path '{0}' filesystem format '{1}' does not match expected format '{2}'.
Expand Down
Loading

0 comments on commit 6845338

Please sign in to comment.