Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 921
Guy Thomas Avatar asked Jan 21 '14 08:01

Guy Thomas


People also ask

How do I add test-NetConnection to PowerShell?

PowerShell Test-Connection Just like ping, uses Test-Connection also the ICMP protocol to test the network connectivity of a network device. In the simplest form, you can type Test-Connection <computername> or <ip-address> to do a quick connectivity test.

What is test-NetConnection in PowerShell?

The Test-NetConnection cmdlet displays diagnostic information for a connection. It supports ping test, TCP test, route tracing, and route selection diagnostics.

Which PowerShell module contains the Get Service cmdlet?

PowerShell console will display all the services which are present in the Services. msc MMC. By default Get-Service cmdlet provides the information about local computer services until the –ComputerName parameter specified for the remote computers. We can also retrieve the dependent services with this cmdlet.

Which cmdlets can be used to ping the local computer?

The Start-Job command uses the Test-Connection cmdlet to ping many computers in an enterprise.


2 Answers

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()
like image 147
Knuckle-Dragger Avatar answered Sep 20 '22 17:09

Knuckle-Dragger


At least Test-NetConnection can be ported back to Windows 7. Just copy folders NetTCPIP, DnsClient, and NetSecurity from the supported Windows machine with the same PowerShell version (Windows 8.1, Windows 10, 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 a module from a 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.

like image 22
Anton Krouglov Avatar answered Sep 18 '22 17:09

Anton Krouglov