-1

My Powershell (called from a CMD BAT file) to show .net versions works fine in win 7 and win 8.1. i.e. info is shown and you get the prompt to continue. In Windows 10 you get no info shown and only AFTER entering the prompt do you see the info flash on the screen before the window is lost.

How do we make this powershell (v5) work in windows 10 ?

thanks

#
# Print out .NET versions installed
#
# IDs from https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx#net_d
#
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select PSChildName, Version, Release, @{
  name="Product"
  expression={
      switch($_.Release) {
        378389 { [Version]"4.5" }
        378675 { [Version]"4.5.1 Win8.1,2012R2" }
        378758 { [Version]"4.5.1 Win8,Win7Sp1" }
        379893 { [Version]"4.5.2" }
        393295 { [Version]"4.6 Win10" }
        393297 { [Version]"4.6 !Win10" }
        394254 { [Version]"4.6.1" }
        394256 { [Version]"4.6.1" }
        394271 { [Version]"4.6.1" }
        394747 { [Version]"4.6.2 Preview" }
        394748 { [Version]"4.6.2 Preview" }
        default {[Version] "? $_.Release" }
      }
    }
}

[string]$MenuOption = Read-Host “`n`t`tEnter <RETURN> to exit”
Greg B Roberts
  • 173
  • 4
  • 14

1 Answers1

1

You can force the pipeline to output the result before calling Read-Host by simply piping to Out-Default:

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select PSChildName, Version, Release, @{
  name="Product"
  expression={
      switch($_.Release) {
        378389 { [Version]"4.5" }
        378675 { [Version]"4.5.1 Win8.1,2012R2" }
        378758 { [Version]"4.5.1 Win8,Win7Sp1" }
        379893 { [Version]"4.5.2" }
        393295 { [Version]"4.6 Win10" }
        393297 { [Version]"4.6 !Win10" }
        394254 { [Version]"4.6.1" }
        394256 { [Version]"4.6.1" }
        394271 { [Version]"4.6.1" }
        394747 { [Version]"4.6.2 Preview" }
        394748 { [Version]"4.6.2 Preview" }
        default {[Version] "? $_.Release" }
      }
    }
} |Out-Default

[string]$MenuOption = Read-Host "`n`t`tEnter <RETURN> to exit"

Be aware that most of your version strings are not actually valid values for [version]

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Thanks Mathias, PS came from existing web sample based off https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx#net_d – Greg B Roberts Oct 18 '16 at 06:04