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

[Bug] Variables are not converted when used as parameter inputs to functions #4

Open
3 tasks done
Richk-1 opened this issue Dec 18, 2024 · 3 comments
Open
3 tasks done
Assignees
Labels
bug Something isn't working

Comments

@Richk-1
Copy link

Richk-1 commented Dec 18, 2024

Prerequisites

PSAppDeployToolkit.Tools version

0.2.1

PSAppDeployToolkit version

4.0.3

Describe the bug

Using Convert-ADTDeployment it doesn't convert -SID $UserProfile.SID to $_.SID for Invoke-HKCURegistrySettingsForAllUsers \ Invoke-ADTAllUsersRegistryAction

[Installation] :: Failed to modify the registry hive for User [XXXX\XXXX] with SID [S-1-5-21-111111111-111111111-9999999999-XXXX]
Error Record:


Message               : The variable '$UserProfile' cannot be retrieved because it has not been set.
                        
FullyQualifiedErrorId : VariableIsUndefined,Invoke-ADTAllUsersRegistryAction

Steps to reproduce

1.Use Convert-ADTDeployment to an older script that is using invoke-HKCURegistrySettingsForAllUsers with the parameter -SID $UserProfile.SID
2.Run new install
3.Check log.

Environment data

OsName               : Microsoft Windows 11 Enterprise
OSDisplayVersion     : 23H2
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsProductName   : Windows 10 Enterprise
WindowsBuildLabEx    : 22621.1.amd64fre.ni_release.220506-1250
OsLanguage           : en-US
OsMuiLanguages       : {en-US}
KeyboardLayout       : en-GB
TimeZone             : (UTC+00:00) Dublin, Edinburgh, Lisbon, London
HyperVisorPresent    : True
CsPartOfDomain       : True
CsPCSystemType       : Mobile


Host:
  Version:      8.0.11
  Architecture: x64
  Commit:       9cb3b725e3
  RID:          win-x64

.NET SDKs installed:
  No SDKs were found.

.NET runtimes installed:
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
@Richk-1 Richk-1 added the bug Something isn't working label Dec 18, 2024
@DanGough
Copy link
Collaborator

This one’s a little trickier to fix since I have to look for variables used in the command then backtrack to where they were defined - e.g. you might not have used $HKCURegistrySettings as the example shows, it could have been named anything. I know how to do it though, so it’ll be worked out soon!

@DanGough
Copy link
Collaborator

Renamed title - this is a more widespread issue that affects any command that requires transformation on the parameter, but the parameter is defined in a separate variable, e.g. these examples work:

Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings {
    Set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'qmenable' -Value 0 -Type DWord -SID $UserProfile.SID
    Set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'updatereliabilitydata' -Value 1 -Type DWord -SID $UserProfile.SID
}
Show-InstallationWelcome -CloseApps 'iexplore,winword,excel'

But the variables are not converted in these examples:

[ScriptBlock]$HKCURegistrySettings = {
    Set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'qmenable' -Value 0 -Type DWord -SID $UserProfile.SID
    Set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'updatereliabilitydata' -Value 1 -Type DWord -SID $UserProfile.SID
}

Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings
$AppsToClose = 'iexplore,winword,excel'
Show-InstallationWelcome -CloseApps $AppsToClose

@DanGough DanGough changed the title [Bug] Convert-ADTDeployment Invoke-HKCURegistrySettingsForAllUsers to Invoke-ADTAllUsersRegistryAction [Bug] Variables are not converted when used as parameter inputs to functions Dec 23, 2024
@DanGough DanGough self-assigned this Jan 9, 2025
@DanGough
Copy link
Collaborator

DanGough commented Feb 6, 2025

I have support for this now in the following branch:
https://github.com/PSAppDeployToolkit/PSAppDeployToolkit.Tools/tree/VariableAssignments

It needs a little more testing before merging in, but it's looking promising - for any functions that require a parameter transformation, and a variable was supplied to the parameter, it will go back to where the variable was assigned.

So this:

[scriptblock]$HKCURegistrySettings = {
    Set-RegistryKey -Key 'HKCU\Software\Test' -Name 'Test' -Value 0 -Type DWord -SID $UserProfile.SID
}
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings

Gets transformed to:

[scriptblock]$HKCURegistrySettings = {
    Set-ADTRegistryKey -Key 'HKCU\Software\Test' -Name 'Test' -Value 0 -Type DWord -SID $_.SID
}
Invoke-ADTAllUsersRegistryAction -ScriptBlock $HKCURegistrySettings

This should in theory work for any parameter that has changed in v4, like -CloseApps on Show-InstallationWelcome - and it's these additional use cases that need to be verified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants