Skip to content

Commit

Permalink
Still more bug fixes
Browse files Browse the repository at this point in the history
All data types will now work properly, even if the -Data parameter is passed a single-element array when that element is of the proper type (which is exactly how the DSC resource calls these commands, incidentally.)
  • Loading branch information
dlwyatt committed Mar 31, 2015
1 parent db6d3b4 commit 56c541f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
28 changes: 23 additions & 5 deletions Commands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,33 @@ function Set-PolicyFileEntry

([Microsoft.Win32.RegistryValueKind]::String)
{
$string = $Data.ToString()
$policyFile.SetStringValue($Key, $ValueName, $string)
$array = @($Data)

if ($array.Count -ne 1)
{
throw 'When -Type is set to String, -Data must be passed a scalar value or single-element array.'
}
else
{
$policyFile.SetStringValue($Key, $ValueName, $array[0].ToString())
}

break
}

([Microsoft.Win32.RegistryValueKind]::ExpandString)
{
$string = $Data.ToString()
$policyFile.SetStringValue($Key, $ValueName, $string, $true)
$array = @($Data)

if ($array.Count -ne 1)
{
throw 'When -Type is set to ExpandString, -Data must be passed a scalar value or single-element array.'
}
else
{
$policyFile.SetStringValue($Key, $ValueName, $array[0].ToString(), $true)
}

break
}

Expand Down Expand Up @@ -198,7 +216,7 @@ function Set-PolicyFileEntry
([Microsoft.Win32.RegistryValueKind]::MultiString)
{
$strings = [string[]] @(
foreach ($item in $data)
foreach ($item in @($Data))
{
$item.ToString()
}
Expand Down
16 changes: 8 additions & 8 deletions PolicyFileEditor.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,25 @@ try
@{
TestName = 'Creates a DWord value properly'
Type = [Microsoft.Win32.RegistryValueKind]::DWord
Data = [UInt32]1
Data = @([UInt32]1)
}

@{
TestName = 'Creates a QWord value properly'
Type = [Microsoft.Win32.RegistryValueKind]::QWord
Data = [UInt64]0x100000000L
Data = @([UInt64]0x100000000L)
}

@{
TestName = 'Creates a String value properly'
Type = [Microsoft.Win32.RegistryValueKind]::String
Data = 'I am a string'
Data = @('I am a string')
}

@{
TestName = 'Creates an ExpandString value properly'
Type = [Microsoft.Win32.RegistryValueKind]::ExpandString
Data = 'My temp path is %TEMP%'
Data = @('My temp path is %TEMP%')
}

@{
Expand All @@ -309,14 +309,14 @@ try
@{
TestName = 'Allows hex strings to be assigned to DWord values'
Type = [Microsoft.Win32.RegistryValueKind]::DWord
Data = '0x12345'
Data = @('0x12345')
ExpectedData = [UInt32]0x12345
}

@{
TestName = 'Allows hex strings to be assigned to QWord values'
Type = [Microsoft.Win32.RegistryValueKind]::QWord
Data = '0x12345789'
Data = @('0x12345789')
ExpectedData = [Uint64]0x123456789L
}

Expand All @@ -330,14 +330,14 @@ try
@{
TestName = 'Allows non-string data to be assigned to String values'
Type = [Microsoft.Win32.RegistryValueKind]::String
Data = 12345
Data = @(12345)
ExpectedData = '12345'
}

@{
TestName = 'Allows non-string data to be assigned to ExpandString values'
Type = [Microsoft.Win32.RegistryValueKind]::ExpandString
Data = 12345
Data = @(12345)
ExpectedData = '12345'
}

Expand Down
4 changes: 2 additions & 2 deletions PolicyFileEditor.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
ModuleToProcess = 'PolicyFileEditor.psm1'
ModuleVersion = '1.2'
ModuleVersion = '1.3'
GUID = '110a2398-3053-4ffc-89d1-1b6a38a2dc86'
Author = 'Dave Wyatt'
CompanyName = 'Home'
Expand Down Expand Up @@ -36,7 +36,7 @@
LicenseUri = 'https://www.apache.org/licenses/LICENSE-2.0.html'
ProjectUri = 'https://github.com/dlwyatt/PolicyFileEditor'
# IconUri = ''
ReleaseNotes = 'Initial release'
ReleaseNotes = 'Bug fixes'
}
}
}
Expand Down

0 comments on commit 56c541f

Please sign in to comment.