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’.
At present, my conclusion is that many PowerShell 4 cmdlets such Test-NetConnection, will only work on Windows 8.1. However, I was wondering if there was a work-around whereby I could import PowerShell 4 modules on my Windows 7 machine.
You cannot, they rely on underlying features of the newer OS (8.0 or 8.1) and cannot be ported back to W7. 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()
At least Test-NetConnection can be ported back to Windows 7. Just copy folders NetTCPIP, DnsClient, NetSecurity from supported Windows machine with same PS version (win8.1, Win10 etc). Folder - C:\Windows\System32\WindowsPowerShell\v1.0\Modules. Then Import-Module -Name C:\Windows\System32\WindowsPowerShell\v1.0\Modules\NetTCPIP -Verbose
Alternatively you can import module from remote machine (say win2012
):
$rsession = New-PSSession -ComputerName win2012
Import-Module NetTCPIP -PSSession $rsession
I have had the same problem on my Windows 7 x64 and both solutions worked for me as of PowerShell 5.1.
Adding to @Anton Krouglov's answer. PowerShell modules are cross platform compatible. So a module copied from Windows Server 2012 R2 x64
can be imported to Windows 7 x86
, and even if you are running as standard user without rights to copy them to C:\Windows\System32\WindowsPowerShell\v1.0\Modules
you can copy it to any local folder, and run
Assuming you copied NetTCPIP
, DnsClient
, NetSecurity
modules from a Server 2012 or higher machine, and save them to a folder you can import them using
Get-ChildItem -Directory .\psmodules | foreach { Import-Module -Name $_.FullName -Verbose}
Test-NetConnection -InformationLevel "Detailed"
As far as I know, Win 2008 R2/win 7 simply doesn't have the counters that the .NET methods use to implement get-netstuff.
New PowerShell version can implement hash compare, etc since this is not related to anything, just a piece of code. But If you want to use for excample Get-NetTCPConnection there is nothing to show. I hope, it helped.
Whilst Powershell 4.0 is available on Windows 7, as Knuckle-Dragger states certain features rely on newer operating system functionality. Unfortunately Test-NetConnection is not available in Windows 7 as stated in the documentation.
Test-Connection, which is present, is basically ping. Test-NetConnection offers much more functionality allowing a choice of things such as TCP ports, protocols, route tracing and information levels.
There is a Send-Ping script available from the ScriptCenter in the Technet gallery but I think this is only really useful if you are stuck on Powershell 3.0 for some reason?
I can only assume you installed the wrong package. Make sure you download the proper package from here.
Below you will see in running Windows 7 Service Pack 1 with Powershell 4 using Test-Connection and Get-FileHash:

来源:https://stackoverflow.com/questions/21252824/how-do-i-get-powershell-4-cmdlets-such-as-test-netconnection-to-work-on-windows