Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xRegistry: Cannot create registry value containing ":" in the path #671

Closed
mkht opened this issue Jan 18, 2020 · 1 comment · Fixed by #672
Closed

xRegistry: Cannot create registry value containing ":" in the path #671

mkht opened this issue Jan 18, 2020 · 1 comment · Fixed by #672

Comments

@mkht
Copy link
Contributor

mkht commented Jan 18, 2020

Description

Attempts to create a registry value with ":" (colons) in the path using the xRegistry resource will fail with an exception.

The DSC configuration that is used to reproduce the issue

Configuration test
{
    Import-DscResource -ModuleName xPSDesiredStateConfiguration

    xRegistry test
    {
        Ensure = 'Present'
        Key = 'HKEY_LOCAL_MACHINE\Software\dsc\mw1.jothgxmws.com:443'
        ValueName = 'TestValue'
        ValueData = '1'
        ValueType = 'DWORD'
        Force = $true
    }
}

Verbose logs showing the problem

詳細: パラメーター ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredSt
ateConfiguration' を使用して操作 'CimMethod の呼び出し' を実行します。
詳細: コンピューター VM1321A1J、ユーザー SID S-1-5-21-3239056254-3345395085-1586727800-1116 から LCM メソッドが呼び出されました。
詳細: [VM1321A1J]: LCM:  [ 開始     設定       ]
詳細: [VM1321A1J]: LCM:  [ 開始     リソース     ]  [[xRegistry]test]
詳細: [VM1321A1J]: LCM:  [ 開始     テスト      ]  [[xRegistry]test]
詳細: [VM1321A1J]:                            [[xRegistry]test] Test-TargetResource is starting for Registry resource with Key HKEY_LOCAL_MACHINE\Sof
tware\dsc\mw1.jothgxmws.com:443
詳細: [VM1321A1J]:                            [[xRegistry]test] Get-TargetResource is starting for Registry resource with Key HKEY_LOCAL_MACHINE\Soft
ware\dsc\mw1.jothgxmws.com:443
詳細: [VM1321A1J]: LCM:  [ 終了     テスト      ]  [[xRegistry]test]  (0.1540 秒)。
PowerShell DSC リソース DSC_xRegistryResource は Test-TargetResource 機能を実行できませんでした。エラー メッセージ: The registry drive HKEY_LOCAL_MACHINE\Software\dsc\mw1.jot
hgxmws.com:443 is invalid. Please update the Key parameter to include a valid registry drive.
パラメーター名:Key 
    + CategoryInfo          : InvalidOperation: (:) []、CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost
 
詳細: [VM1321A1J]: LCM:  [ 終了     設定       ]
SendConfigurationApply 関数が失敗しました。
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost
 
詳細: 操作 'CimMethod の呼び出し' が完了しました。
詳細: 構成ジョブが完了するまでにかかった時間は 0.8 秒です

Suggested solution to the issue

The Get-PathRoot function has a problem. It does not returns proper root drive when paths containing colons.

function Get-PathRoot
{
[OutputType([System.String])]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Path
)
$pathParent = Split-Path -Path $Path -Parent
$pathRoot = $Path
while (-not [System.String]::IsNullOrEmpty($pathParent))
{
$pathRoot = Split-Path -Path $pathParent -Leaf
$pathParent = Split-Path -Path $pathParent -Parent
}
return $pathRoot
}

@mkht
Copy link
Contributor Author

mkht commented Jan 18, 2020

This issue only occurs if we specify the Common registry style for the root of the path like HKEY_LOCAL_MACHINE\.... and does not occur when specifying a PSDrive style path like HKLM:\....

Sample DSC configuration that has issue.

Configuration test
{
    Import-DscResource -ModuleName xPSDesiredStateConfiguration

    xRegistry test
    {
        Ensure = 'Present'
        Key = 'HKEY_LOCAL_MACHINE\Software\dsc\mw1.jothgxmws.com:443'
        ValueName = 'TestValue'
        ValueData = '1'
        ValueType = 'DWORD'
        Force = $true
    }
}

Sample DSC configuration that has NOT issue.

Configuration test
{
    Import-DscResource -ModuleName xPSDesiredStateConfiguration

    xRegistry test
    {
        Ensure = 'Present'
        Key = 'HKLM:\Software\dsc\mw1.jothgxmws.com:443'
        ValueName = 'TestValue'
        ValueData = '1'
        ValueType = 'DWORD'
        Force = $true
    }
}

mkht added a commit to mkht/xPSDesiredStateConfiguration that referenced this issue Jan 18, 2020
mkht added a commit to mkht/xPSDesiredStateConfiguration that referenced this issue Jan 24, 2020
PlagueHO pushed a commit that referenced this issue Jan 24, 2020
…n the path. (#672)

* Add unit & intergration tests

* Fix issue #671

* Update CHANGELOG.md
mkht added a commit to mkht/xPSDesiredStateConfiguration that referenced this issue Feb 23, 2020
…n the path. (dsccommunity#672)

* Add unit & intergration tests

* Fix issue dsccommunity#671

* Update CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant