I am running the toolkit on a win 7 box with powershell 3 installed. I added a few functions to the installation section, but the code crashed prior to anything I added. As you can see in the error, it crashed on line 90 which is
If ($DisableLogging) { . $moduleAppDeployToolkitMain -DisableLogging } Else { . $moduleAppDeployToolkitMain }
specifically character 90, which is the else clause. Any help would be appreciated.
I have a screen shot of the error but using the img button doesn’t seem to work on this forum.
The error says failed to load, cannot index into a null array. right before that, there is a line of output that says
Get-RegistryKey (HKEY_Users\sidxxxxx\control panel\international\user profile] does not exist.
Seems like not getting the registry key fails to populate an array?
The code is not crashing prior to anything you added. It is crashing where you added something. That line dot sources the main toolkit. If there is some kind of parsing error when it tries to dot source the toolkit, then it will fail on that line. Go over our code again to see what might be the issue. Also, the way you’re calling Get-RegistryKey above does not look right; look at some of the examples for that function to see how it should be used.
Thanks for your reply Muhammad! I am not calling Get-Registry key, I was merely trying to give you the text of the line prior to the error. In the PowerShell command window there is a bunch of information about the toolkit running, which is very helpful, and the line prior to the error talks about a Get-Registry key function being called. I believe the $HKULanguages array is empty after going through all of these ifs, and then trying to get values out of the empty array is throwing an error.
I’m looking in the Main PS file, and I can see the section that fails. It is the section which has these ifs
<code> # Read language for Win Vista/Win 7 machines
If (-not $HKULanguages) {
[string[]]$HKULanguages = Get-RegistryKey -Key 'HKCU\Control Panel\Desktop' -Value 'PreferredUILanguages' -SID $RunAsActiveUser.SID
}
If (-not $HKULanguages) {
[string[]]$HKULanguages = Get-RegistryKey -Key 'HKCU\Control Panel\Desktop\MuiCached' -Value 'MachinePreferredUILanguages' -SID $RunAsActiveUser.SID
}
If (-not $HKULanguages) {
[string[]]$HKULanguages = Get-RegistryKey -Key 'HKCU\Control Panel\International' -Value 'LocaleName' -SID $RunAsActiveUser.SID
}</code>
What version of the toolkit are you on?
Also, can you manually check those registry keys? Are none of them populated in your registry hive? At least one of them should be there, and if so, then the variable should not be empty.
the main app ps has a version of 3.6.5
I will check the keys and report back. Quick question, how does $HKULanguages get populated? I don’t see a reference to in prior to the set of IF statements. In my lab I see it has a value of en-us, but on my customer’s machine I am guessing it will be blank. I’ll look…
I would recommend updating to the latest 3.6.7 as there was one fix related to HKULanguages on Win8 machines. HKULanguages is populated from the HKCU registry hive…from the paths listed in that section.
looks like the new version fixed the issue. Thanks Muhamnad! One more question, do you have any idea how the $HKULanguages array is populated, just for my own knowledge?
If a user is logged into the machine, it reads the user’s regional language display settings from the registry. If multiple language packs are installed, then the first language in the array is the display language.
I got all that, I was just confused on which line of code the array actually got populated.
That just depends on which ever registry path first provides the data we are looking for. That’s why are are searching for the data in multiple registry key paths.
<code> If ($RunAsActiveUser) {
# Read language defined by Group Policy
If (-not $HKULanguages) {
[string[]]$HKULanguages = Get-RegistryKey -Key 'HKLM:SOFTWARE\Policies\Microsoft\MUI\Settings' -Value 'PreferredUILanguages'
}</code>
I see where $RunAsActiveUser get populated, that all makes sense. The string array $HKULanguages is used just below $RunAsActiveUser, and this is the first time $HKULanguages is used in this script, meaning it was never populated prior to hitting this IF statement. But, tracing in PowerShell ISE shows the value of this array as EN-US, so it is getting populated, but where? Where in the code?
That is the only section of the script where that variable gets populated. That variable is not referenced anywhere else. PowerShell ISE sometimes does not behave the same as the PowerShell console. It hangs onto variables and data from one execution to the next. Completely exit PowerShell ISE, launch it again, debug the code and step through it line by line and you should see when that variable first gets populated.
Aah, that could be the case and that would make sense. It was driving me crazy that this array had a value before it was ever assigned a value lol.
PowerShell ISE is goofy!