0

can someone tell me why the following command has different results in Powershell and Powershell_ISE?

 $Software = "*Native*SQL*"  
 $Result = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -like $Software}

Powershell: $Result provides the desired data
Powershell_ISE: $Result does not provide any data

For the test I opened the script on my support machine in the ISE and wondered why the output could not find a SQL Native Client even though it appeared in the registry.

On another computer it works fine in both environments.
I use this in a group policy for software distribution and am wondering why only about 250 out of 400 computers install software.

OS: Windows 10 - 20H2 an Windows 10 1909

Best regards!

mklement0
  • 382,024
  • 64
  • 607
  • 775
Daniel4711
  • 402
  • 10
  • 24
  • 3
    Are you by any chance running the 32-bit version of ISE (x86)? Check `[System.Environment]::Is64BitProcess` in both environments – Mathias R. Jessen Apr 22 '21 at 16:38
  • 1
    As an aside re the PowerShell ISE: It is [no longer actively developed](https://learn.microsoft.com/en-us/powershell/scripting/components/ise/introducing-the-windows-powershell-ise#support) and [there are reasons not to use it](https://stackoverflow.com/a/57134096/45375) (bottom section), notably not being able to run PowerShell [Core] 6+. The actively developed editor that offers the best PowerShell development experience, across platforms, is [Visual Studio Code](https://code.visualstudio.com/), combined with its PowerShell extension. – mklement0 Apr 22 '21 at 16:40
  • @MathiasR.Jessen You are right... The ISE was started with me as X86 and therefore did not return a result. I just don't understand why. In addition, I am actually not concerned with the ISE but with the general call of the script during GPO processing. – Daniel4711 Apr 22 '21 at 17:00
  • 1
    @mklement0 Thanks for the hint. That's a shame because I actually think the ISE environment is very good for me. I mostly use the snippets to do everyday tasks in the ISE. When developing scripts, I mostly use functions and develop in the ISE. I'll take a look at Visual Studio Code and then I think I'd better switch! – Daniel4711 Apr 22 '21 at 17:03
  • 2
    @Daniel4711 To answer "why", you need to learn about [registry redirection](https://learn.microsoft.com/en-us/windows/win32/winprog64/registry-redirector) - a 32-bit process trying to resolve `HKLM:\SOFTWARE\...` is transparently redirected to `HKLM:\SOFTWARE\Wow6432Node\...` and therefore only ever sees "half" of the entries under the SOFTWARE sub key – Mathias R. Jessen Apr 22 '21 at 17:04
  • @MathiasR.Jessen Registry redirection is a good indication. I often use the above-mentioned query in an installation script which is processed via a group policy when the computer is started. This is divided into many functions which at the beginning usually check the registry for the display version. I've never had any problems with it before. Should I change the query above? – Daniel4711 Apr 22 '21 at 17:12
  • @Daniel4711, without a doubt the ISE has great features that Visual Studio Code is still catching up to, and I know that it's hard to give up an IDE one is used to. The silver lining is that the behavioral differences between the ISE and regular console windows that were always problematic will go away. – mklement0 Apr 22 '21 at 17:20
  • 1
    @mklement0 I have installed the VSC and will familiarize myself with it. Many Thanks! – Daniel4711 Apr 22 '21 at 17:53

0 Answers0