Comparision Setting RegKeys in v3 vs v4

Hey Guys,

in my previous v3.10 Deployments i used some Costum RegKeys to detect Applications.

The Code i used in POST-Installation is this:

		[String]$appCurrentDate = Get-Date -Format "dd.MM.yyyy"		
		Set-RegistryKey -Key HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$appVendor\$appName -Name 'Install' -Value $appRevision -Type String
        Set-RegistryKey -Key HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$appVendor\$appName -Name 'PackageDate' -Value $appScriptDate -Type String
        Set-RegistryKey -Key HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$appVendor\$appName -Name 'Publisher' -Value $appScriptAuthor -Type String
        Set-RegistryKey -Key HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$appVendor\$appName -Name 'Version' -Value $appVersion -Type String
        Set-RegistryKey -Key HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$appVendor\$appName -Name 'InstallDate' -Value $appCurrentDate -Type String

I then checked in SCCM whether these keys were available and this works quite well.

After Updating to 4.17 the Code looks like this:

		[String]$appCurrentDate = Get-Date -Format "dd.MM.yyyy"		
		Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'Install' -Value $adtSession.AppRevision -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'PackageDate' -Value $adtSession.AppScriptDate -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'Publisher' -Value $adtSession.AppScriptAuthor -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'Version' -Value $adtSession.AppVersion -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'InstallDate' -Value $appCurrentDate -Type String

But now its not creating the expected Keys...

Im Pretty sure its just a thinking mistake by me, hopefully anyone see the Part were it goes wrong.

I think your script is seeing .AppVendor and .AppName as Text rather than expanding them.
I don't know for certain (someone else may come along and confirm), but I think this may be either because the way this is represented in your code needs changing
From this:

[String]$appCurrentDate = Get-Date -Format "dd.MM.yyyy"		
		Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'Install' -Value $adtSession.AppRevision -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'PackageDate' -Value $adtSession.AppScriptDate -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'Publisher' -Value $adtSession.AppScriptAuthor -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'Version' -Value $adtSession.AppVersion -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$adtSession.AppVendor\$adtSession.AppName -Name 'InstallDate' -Value $appCurrentDate -Type String**strong text**

To this:

[String]$appCurrentDate = Get-Date -Format "dd.MM.yyyy"		
		Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$($adtSession.AppVendor)\$($adtSession.AppName) -Name 'Install' -Value $($adtSession.AppRevision) -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$($adtSession.AppVendor)\$($adtSession.AppName) -Name 'PackageDate' -Value $($adtSession.AppScriptDate) -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$($adtSession.AppVendor)\$($adtSession.AppName) -Name 'Publisher' -Value $($adtSession.AppScriptAuthor) -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$($adtSession.AppVendor)\$($adtSession.AppName) -Name 'Version' -Value $($adtSession.AppVersion) -Type String
        Set-ADTRegistryKey -LiteralPath HKEY_LOCAL_MACHINE\SOFTWARE\SCCM_Software\$($adtSession.AppVendor)\$($adtSession.AppName) -Name 'InstallDate' -Value $appCurrentDate -Type String

Note extra $() bracketing around your variables
or the $ADTSession has been closed before you are calling these variables - Advice from others required here...

2 Likes

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