-
Notifications
You must be signed in to change notification settings - Fork 1
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
Comments
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! |
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 |
I have support for this now in the following branch: 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. |
Hi Dan,
Thanks for the update. I did get 0.2.3 tools installed and tried a convert.
The only issues I will have to look out for, is the 15-18 custom Variables in have in the Variables below the standard PSADT variables in the head of the script, do not get copied over in a v3 to v4 conversion. That is easily tweaked after the conversion of a converted v4 script.
The other issue, is any variable with a comment, does not get converted. I personally use Show-InstallationPrompt for all sections, since our PSADT scripts write data to ServiceNow (Time installed, pre-version, end version, Product key, total time for the install, etc.) It is not a pretty script when I am done, but the business requested this extra script that interfaces with the ServiceNow helpdesk API.
Anyway, that was the last thing I will have to verify, is any commented function will probably not get converted from v3 to v4 and I will need to remember to go through the scripts and fix that issue.
Thanks for the work on the tools part, as some of us have really customized the PSADT to the fullest.
Jeff Little
…________________________________
From: Dan Gough ***@***.***>
Sent: Thursday, February 6, 2025 11:36 AM
To: PSAppDeployToolkit/PSAppDeployToolkit.Tools ***@***.***>
Cc: Jeff L. ***@***.***>; Manual ***@***.***>
Subject: Re: [PSAppDeployToolkit/PSAppDeployToolkit.Tools] [Bug] Variables are not converted when used as parameter inputs to functions (Issue #4)
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.
—
Reply to this email directly, view it on GitHub<#4 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BEEMQMNMTS7IQMKMXZZQ22L2OOMTJAVCNFSM6AAAAABT3EM7XSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNBQGU2TMNBSGE>.
You are receiving this because you are subscribed to this thread.
|
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
The text was updated successfully, but these errors were encountered: