PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

Networking Introspection CmdLets are not available cross-platform

Open chrisfcarroll opened this issue 8 years ago • 45 comments

CmdLets in the NetTCPIP & other Net* modules are not available cross-platform. My use-case: we use powershell + netCore as a cross-platform develop & deploy solution. (It's great!) If I might offer an order of priorities based on that use-case, I would prioritise

  • 'Get-' and 'Test-' CmdLets over 'Set-' & mutators
  • NetTcpIp over other Net* modules

Rationale: In container and serverless application/service deployment, the ability (and hence the need) to mutate hardware and security configuration is limited; but the need to inspect network configuration does not go away.

So top of my list are:

Get-NetIPAddress
Test-NetConnection
Get-NetIPConfiguration
Get-NetIPInterface
Resolve-DnsName
Find-NetRoute

Environment data


> $PSVersionTable                                                                                                                                              

Name                           Value                                                                                                                                         
----                           -----                                                                                                                                         
PSVersion                      6.0.1                                                                                                                                         
PSEdition                      Core                                                                                                                                          
GitCommitId                    v6.0.1                                                                                                                                        
OS                             Darwin 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64                                 
Platform                       Unix                                                                                                                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                           
SerializationVersion           1.1.0.1                                                                                                                                       
WSManStackVersion              3.0  

> $PSVersionTable
PSVersion                      6.0.0-rc
PSEdition                      Core
GitCommitId                    v6.0.0-rc
OS                             Linux 4.4.51-40.58.amzn1.x86_64 #1 SMP Tue Feb 28 21:57:17 UTC 2017
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

chrisfcarroll avatar Jan 31 '18 11:01 chrisfcarroll

Many if not all of the net* modules are based on CIM classes that are only available on Windows 8 and later. Either those CIM classes would have to be ported to the other platforms - currently no CIM classes have been or are earmaked for porting as far as I'm aware - or the cmdlets would need to be rewritten to use the appropriate method of retrieving the data on each platform which is a non-trivial task

RichardSiddaway avatar Jan 31 '18 12:01 RichardSiddaway

Advanced and ported Test-Connection cmdlet #5328

Resolve-DnsName can be easily implemented (with some seizures).

The remaining cmdlets are more difficult to implement because of the lack of standard APIs.

iSazonov avatar Jan 31 '18 12:01 iSazonov

@iSazonov could you maybe share the Resolve-DnsName code? Would be very helpful :)

GrimSmiler avatar Jun 28 '18 13:06 GrimSmiler

@GrimSmiler I am not owner the cmdlet.. :-) MSFT is an owner. And the cmdlet is out of the repo.

I'd can re-create the cmdlet in the repo if we would get encouragement. Our policy requires the creation of an RFC. You could grab this if you want to get this cmdlet.

iSazonov avatar Jun 28 '18 13:06 iSazonov

@iSazonov Then shall we create a feature request in https://github.com/dotnet/core or maybe https://github.com/dotnet/corefx about accessing such features?

FranklinYu avatar Dec 11 '18 22:12 FranklinYu

@FranklinYu Seems it is out of CoreFX. CoreFX implements only base APIs. Interface management and route management is more high API level. Perhaps we could consider CIM. In any case, you need first do more research before make feature requests.

iSazonov avatar Dec 12 '18 06:12 iSazonov

@iSazonov I'm not familiar with CIM, but I thought it's only available on Windows, isn't it?

FranklinYu avatar Dec 12 '18 15:12 FranklinYu

@FranklinYu There is OMI project for portable implementation of CIM https://cloudblogs.microsoft.com/windowsserver/2012/06/28/open-management-infrastructure/

iSazonov avatar Dec 12 '18 19:12 iSazonov

IIUC if we implement those cmdlets in PowerShell with CIM, we need to include OMI in the package for non-Windows operating system, right?

FranklinYu avatar Dec 12 '18 20:12 FranklinYu

OMI is another project and you can freely install OMI on non-Windows systems.

The current plan for the repo is the reverse — eliminate dependence on OMI native client library and implement WSMan client on managed code to get better compatibility for all platforms. @SteveL-MSFT Could you please more clarify?

iSazonov avatar Dec 13 '18 05:12 iSazonov

@iSazonov I’m having some issue looking up the documentation. Resolve-DnsName only shows “Windows 8.1 and Windows Server 2012 R2” as latest version. Is it provided by a PowerShell package instead? Like NetworkingDsc?

FranklinYu avatar Dec 16 '18 17:12 FranklinYu

No, it is a Windows component.

iSazonov avatar Dec 16 '18 18:12 iSazonov

@iSazonov Then I don’t quite understand why it says that. When I select “Windows 10” in the Product list, it says

The requested page is not available for Windows 10 and Windows Server 2016 PowerShell. You have been redirected to the newest product version this page is available for.

So the Cmdlet works, but it is no longer documented? Is it deprecated?

FranklinYu avatar Dec 16 '18 18:12 FranklinYu

Might be a documentation issue? I have Resolve-DnsName on PS Core 6.1.0 with Windows 10.

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Resolve-DnsName                                    1.0.0.0    DnsClient

vexx32 avatar Dec 16 '18 18:12 vexx32

It looks as doc issue. You could report on the web page or PowerShell-Docs repo.

iSazonov avatar Dec 16 '18 18:12 iSazonov

@vexx32 Resolve-DnsName works in your PS Core? I installed PS Core 6.1.0 on my Windows 10 and Resolve-DnsName is not found. It only works with the Windows PowerShell 5 that came with Windows 10.

FranklinYu avatar Dec 16 '18 21:12 FranklinYu

Ah, yeah. I don't think I changed my $env:PSModulePath, but I might have. It does work but I'm not sure if PS Core searches in the WinPS module paths by default or if I added that into my environment variables directly at some point.

vexx32 avatar Dec 16 '18 22:12 vexx32

If you look C:\Windows\System32\WindowsPowerShell\v1.0\Modules\DnsClient\DnsClient.psd1 on Windows 10 1809 you will see CompatiblePSEditions = @('Desktop','Core'). The latest Windows 10 version has many such updated modules compatible with PowerShell Core 6.1. This was announced in https://blogs.msdn.microsoft.com/powershell/2018/09/13/announcing-powershell-core-6-1/

iSazonov avatar Dec 17 '18 17:12 iSazonov

@iSazonov I can confirm with Windows 10 1809. This is not available for Windows 10 1803 (which is still the majority). I'm wondering how do I write my own Cmdlet that are compatible with both Windows PowerShell and PowerShell Core, like DnsClient in this case?

FranklinYu avatar Dec 18 '18 17:12 FranklinYu

@FranklinYu I recently wrote some docs on writing portable modules. It's not merged yet as it's still under review, but you can take a look at the PR for the content.

Regarding OMI above. My current recommendation is to not take a dependency on OMI.

SteveL-MSFT avatar Dec 18 '18 17:12 SteveL-MSFT