【问题标题】:Why Powershell Where | Select is different in Windows 10 [duplicate]为什么选择 Powershell? Windows 10中的选择不同[重复]
【发布时间】:2016-10-18 03:39:20
【问题描述】:

我的 Powershell(从 CMD BAT 文件调用)显示 .net 版本在 win 7 和 win 8.1 中运行良好。 即显示信息,您会得到继续的提示。 在 Windows 10 中,您不会显示任何信息,只有在输入提示后,您才会在窗口丢失之前看到屏幕上的信息闪烁。

我们如何让这个 powershell (v5) 在 windows 10 中工作?

谢谢

#
# 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”

【问题讨论】:

    标签: windows powershell windows-10


    【解决方案1】:

    您可以在调用Read-Host 之前强制管道输出结果,只需通过管道传递到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"
    

    请注意,您的大多数版本字符串实际上不是 [version] 的有效值

    【讨论】:

    猜你喜欢
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2023-02-07
    相关资源
    最近更新 更多