Help creating registry keys not value

I am trying to create new registry keys under HKCU in which creates portals and for all users.

However, it appears to fails to modify the registry key. Just to note we are running Intune AAD in which these machines are enrolled and have a unique SID starting with S-1-12-1 in which domain joined machine SID accounts have a SID of [S-1-5-20]

## <Perform Post-Installation tasks here>
		
		[scriptblock]$HKCURegistrySettings = {
    
			New-Item -Path 'HKCU:\SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\x.x.x.x' –Force -SID $UserProfile.SID
			New-Item -Path 'HKCU:\SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\x.x.x.x' –Force -SID $UserProfile.SID
			New-Item -Path 'HKCU:\SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\x.x.x.x' –Force -SID $UserProfile.SID
			New-Item -Path 'HKCU:\SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\x.x.x.x' –Force -SID $UserProfile.SID
		}

		Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings | Start-Sleep -Seconds 10 | 
		Stop-ServiceAndDependencies -Name 'PanGPS' |  Start-Sleep -Seconds 10 | Start-ServiceAndDependencies -Name 'PanGPS'

Log

[Post-Installation] :: Get the User Profile Path, User Account SID, and the User Account Name for all users that log onto the machine.	Get-UserProfiles	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Convert the SID [S-1-12-1-2405667515-1295024182-656177071-2175736442] to an NT Account name.	ConvertTo-NTAccountOrSID	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Convert the SID [S-1-5-18] to an NT Account name.	ConvertTo-NTAccountOrSID	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Convert the SID [S-1-5-19] to an NT Account name.	ConvertTo-NTAccountOrSID	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Convert the SID [S-1-5-20] to an NT Account name.	ConvertTo-NTAccountOrSID	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: The User [azuread\user] registry hive is already loaded in path [HKEY_USERS\S-1-12-1-2405667515-1295024182-656177071-2175736442].	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Execute ScriptBlock to modify HKCU registry settings for all users.	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Failed to modify the registry hive for User [azuread\user] with SID [S-1-12-1-2405667515-1295024182-656177071-2175736442] 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_3\Deploy-Application.ps1:151 char:115
+ ... alProtect\Settings\x.x.x.x' –Force -SID $UserPr ...
+                                                              ~~~~
	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Load the User [Default User] registry hive in path [HKEY_USERS\S-1-5-21-Default-User].	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Execute ScriptBlock to modify HKCU registry settings for all users.	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Failed to modify the registry hive for User [Default User] with SID [S-1-5-21-Default-User] 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_3\Deploy-Application.ps1:151 char:115
+ ... alProtect\Settings\x.x.x.x' –Force -SID $UserPr ...
+                                                              ~~~~
	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Unload the User [Default User] registry hive in path [HKEY_USERS\S-1-5-21-Default-User].	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: Bypassing Close-InstallationProgress [Mode: NonInteractive]	Close-InstallationProgress	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: PaloAltoNetworks_GlobalProtect_5.2.4_x64_EN_01 Installation completed with exit code [0].	Exit-Script	3/11/2021 11:36:57 PM	5572 (0x15C4)
[Post-Installation] :: -------------------------------------------------------------------------------	Exit-Script	3/11/2021 11:36:57 PM	5572 (0x15C4)

Thanks!

You are supposed to use Set-RegistryKey not New-Item. New-Item does not have a SID parameter.

Hi Luki412,

Does the Set-Registrykey actually create the sub key if it does not exist? Reading the documentation it appears to only set a registry value under the key.

Here is a screenshot of what I am trying to create under HCKU user and for all users.

If the key does not exist, create it. I was under the impression Set-Registrykey only create values under a key.

I have tried using Set-Registrykey and it just fails.

[scriptblock]$HKCURegistrySettings = {
    
			Set-RegistryKey -Key 'SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\' -Name 'x.x.x.x' -SID $UserProfile.SID
                        Set-RegistryKey -Key 'SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\' -Name 'a.a.a.a' -SID $UserProfile.SID
                       Set-RegistryKey -Key 'SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\' -Name 'b.b.b.b' -SID $UserProfile.SID
                       Set-RegistryKey -Key 'SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\' -Name 'c.c.c.c' -SID $UserProfile.SID

		}

		Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings | Start-Sleep -Seconds 10 | 
		Stop-ServiceAndDependencies -Name 'PanGPS' |  Start-Sleep -Seconds 10 | Start-ServiceAndDependencies -Name 'PanGPS'

log

[Post-Installation] :: Get the User Profile Path, User Account SID, and the User Account Name for all users that log onto the machine.	Get-UserProfiles	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Convert the SID [S-1-12-1-2405667515-1295024182-656177071-2175736442] to an NT Account name.	ConvertTo-NTAccountOrSID	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Convert the SID [S-1-5-18] to an NT Account name.	ConvertTo-NTAccountOrSID	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Convert the SID [S-1-5-19] to an NT Account name.	ConvertTo-NTAccountOrSID	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Convert the SID [S-1-5-20] to an NT Account name.	ConvertTo-NTAccountOrSID	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: The User [azurad\aduser] registry hive is already loaded in path [HKEY_USERS\S-1-12-1-2405667515-1295024182-656177071-2175736442].	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Execute ScriptBlock to modify HKCU registry settings for all users.	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Failed to set value [] for registry key [HKCUSOFTWARE\Palo Alto Networks\GlobalProtect\Settings] [x.x.x.x]. 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_1\AppDeployToolkit\AppDeployToolkitMain.ps1:3962 char:4
+ Throw "Unable to detect target registry hive in string [$ ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Set-RegistryKey	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Failed to set value [] for registry key [HKCUSOFTWARE\Palo Alto Networks\GlobalProtect\Settings] [a.a.a.a]. 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_1\AppDeployToolkit\AppDeployToolkitMain.ps1:3962 char:4
+             Throw "Unable to detect target registry hive in string [$ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set-RegistryKey	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Failed to set value [] for registry key [HKCUSOFTWARE\Palo Alto Networks\GlobalProtect\Settings] [b.b.b.b]. 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_1\AppDeployToolkit\AppDeployToolkitMain.ps1:3962 char:4
+ Throw "Unable to detect target registry hive in string [$ ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Set-RegistryKey	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Failed to set value [] for registry key [HKCUSOFTWARE\Palo Alto Networks\GlobalProtect\Settings] [c.c.c.c]. 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_1\AppDeployToolkit\AppDeployToolkitMain.ps1:3962 char:4
+             Throw "Unable to detect target registry hive in string [$ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set-RegistryKey	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Load the User [Default User] registry hive in path [HKEY_USERS\S-1-5-21-Default-User].	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 9:47:30 PM	12876 (0x324C)
[Post-Installation] :: Execute ScriptBlock to modify HKCU registry settings for all users.	Invoke-HKCURegistrySettingsForAllUsers	3/11/2021 9:47:31 PM	12876 (0x324C)
[Post-Installation] :: Failed to set value [] for registry key [HKCUSOFTWARE\Palo Alto Networks\GlobalProtect\Settings] [x.x.x.x]. 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_1\AppDeployToolkit\AppDeployToolkitMain.ps1:3962 char:4
+ Throw "Unable to detect target registry hive in string [$ ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Set-RegistryKey	3/11/2021 9:47:31 PM	12876 (0x324C)
[Post-Installation] :: Failed to set value [] for registry key [HKCUSOFTWARE\Palo Alto Networks\GlobalProtect\Settings] [a.a.a.a]. 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_1\AppDeployToolkit\AppDeployToolkitMain.ps1:3962 char:4
+             Throw "Unable to detect target registry hive in string [$ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set-RegistryKey	3/11/2021 9:47:31 PM	12876 (0x324C)
[Post-Installation] :: Failed to set value [] for registry key [HKCUSOFTWARE\Palo Alto Networks\GlobalProtect\Settings] [b.b.b.b]. 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_1\AppDeployToolkit\AppDeployToolkitMain.ps1:3962 char:4
+ Throw "Unable to detect target registry hive in string [$ ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Set-RegistryKey	3/11/2021 9:47:31 PM	12876 (0x324C)
[Post-Installation] :: Failed to set value [] for registry key [HKCUSOFTWARE\Palo Alto Networks\GlobalProtect\Settings] [c.c.c.c]. 
Error Record:
-------------At C:\Windows\IMECache\da61664f-0bad-4b00-b72f-bbc0397f1bbe_1\AppDeployToolkit\AppDeployToolkitMain.ps1:3962 char:4
+             Throw "Unable to detect target registry hive in string [$ ...

Thanks.

Yes it creates and changes registry keys and values.

Everything that looks like a folder in regedit is a part of the key. You only need to use the -Name and -Value when you need properties in that key.

Also, you didnt have the full path to the key. You need to enter the hive.

Set-RegistryKey -Key 'HKEY_CURRENT_USER\SOFTWARE\Palo Alto Networks\GlobalProtect\Settings\x.x.x.x' -SID $UserProfile.SID

Thanks. It appears to work now.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.