How do I get PowerShell 4 cmdlets such as Test-NetConnection to work on Windows 7?

后端 未结 7 798
刺人心
刺人心 2021-02-07 05:27

The situation. On a Windows 7 SP1 machine, I have updated with Windows6.1-KB2819745-x64-MultiPkg.msu. Furthermore, in PowerShell $PSVersionTable now reports ‘PSVersion 4.0’.

相关标签:
7条回答
  • 2021-02-07 06:04

    You cannot. They rely on the underlying features of the newer OS (8.0 or 8.1) and cannot be ported back to Windows 7 . The alternative is to write your own functions / modules to replicate the new cmdlets using .NET framework methods.

    For instance, the Get-FileHash cmdlet is a one-liner in PowerShell 4.0, but to replicate in 2.0 we have to use .NET.

    PowerShell v4

    Get-FileHash -Algorithm SHA1 "C:\Windows\explorer.exe"
    

    PowerShell v2

    $SHA1 = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
    $file = [System.IO.File]::Open("C:\Windows\explorer.exe",[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
    [System.BitConverter]::ToString($SHA1.ComputeHash($file)) -replace "-",""
    $file.Close()
    
    0 讨论(0)
提交回复
热议问题