2016-10-18 22 views
-1

我的Powershell(從CMD BAT文件調用)以顯示.net版本在win 7和win 8.1中工作正常。 即顯示信息,您將看到提示繼續。 在Windows 10中,您不會顯示任何信息,只有在輸入提示後,纔會在窗口丟失之前在屏幕上看到信息閃爍。爲什麼Powershell在哪裏|選擇是不同的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」 

回答

1

您可以強制管道輸出的結果通過簡單的管道,以Out-Default調用Read-Host前:

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]

+0

感謝Mathias,PS來自基於https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx#net_d的現有Web示例 –

相關問題