PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
44.62k stars 7.22k forks source link

Get-Help Add-Computer Reveals help for Select-XML #12097

Closed teskemj closed 3 years ago

teskemj commented 4 years ago

Steps to reproduce

get-help add-computer
get-help add-computer -examples

Expected behavior

Help output for add-computer
Examples for add-computer

Actual behavior

Updates help each time and returns select-xml help
Examples for select-xml

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
MaximoTrinidad commented 4 years ago

It seems there is a conflict between core modules: PS7 vs. Windows PowerShell

PS C:\Users\max_t> Get-Module -L Microsoft.PowerShell.Management                                                                                                                                                                                                                                                                                                            Directory: C:\program files\powershell\7\Modules                                                                                                                                                                                            ModuleType Version    PreRelease Name                                PSEdition ExportedCommands                         ---------- -------    ---------- ----                                --------- ----------------                         Manifest   7.0.0.0               Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Get-Clipbo…                                                                                                                             Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules                                                                                                                                                                               ModuleType Version    PreRelease Name                                PSEdition ExportedCommands                         ---------- -------    ---------- ----                                --------- ----------------                         Manifest   3.1.0.0               Microsoft.PowerShell.Management     Core,Desk {Add-Content, Clear-Content, Clear-Item…                                                                                                                         PS C:\Users\max_t> 

It can't find it the Add-Computer help files and is returning something else. And, it doesn't even work if you use the following command:

Import-Module Microsoft.PowerShell.Management -UseWindowsPowerShell                                                                                                             

UpdateHelp0_2020-03-10_17-03-52

Something is going on! :)

teskemj commented 4 years ago

Cool...I was just poking around between Windows Powershell and 7 as I'm onboarding systems and wanted to test out 7.

doctordns commented 4 years ago

I am using PowerShell 7.0 as released in Windows 10. This fails here too.

2020-03-11_10-47-28

teskemj commented 4 years ago

The command executes, but look at the help. It displays the help for select-XML :)

MaximoTrinidad commented 4 years ago

@doctordns

This happens to me in the beginning, then I realized that the help for Add-Computer is not equal to the Select-XML help. Unless I'm missing something.

In my case, I got PowerShell 7 install in of my environments (Physical and VM's) and the Add-Computer cmdlet is not available at first. You said that works! Hum!

AddComp_01_2020-03-11_10-02-51

I wonder! How did you install PowerShell 7? I use the "PowerShell-7.0.0-win-x64.msi". :)

doctordns commented 4 years ago

Installed using the MIS via Install-PowerShell7,ps1 script on github. Have you tried Update-Help??

doctordns commented 4 years ago

OK - so I tried this on a newly created DC:

2020-03-11_17-54-21

ANd if I update the help , the examples reutrn

NO Idea why the earlier command worked like that!!!

MaximoTrinidad commented 4 years ago

@doctordns

Yes! It works in Windows PowerShell but not in PowerShell 7.0.

AddComp_02_2020-03-11_14-04-31

It's possible there's a conflict of modules that the Get-Help can't resolve.

AddComp_03_2020-03-11_14-04-31

:)

SteveL-MSFT commented 4 years ago

I believe this is a side effect of https://github.com/PowerShell/PowerShell/issues/11419. Going through the code, Get-Help initiates command discovery and finds this command in the Windows PowerShell Management module, so uses that index into the PS7 Management module help which shows the wrong content.

anmenaga commented 4 years ago

Can somebody with the repro please try it on the latest daily build? Thank you.

To install the latest daily build: Invoke-Expression "& { $(Invoke-RestMethod 'https://aka.ms/install-powershell.ps1') } -daily"

PS C:\> $psversiontable.PSVersion

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      0      0      daily.20200322

PS C:\> get-help add-computer

NAME
    Add-Computer

SYNTAX
    Add-Computer [-DomainName] <string> -Credential <pscredential> [-ComputerName
    <string[]>] [-LocalCredential <pscredential>] [-UnjoinDomainCredential
MaximoTrinidad commented 4 years ago

@anmenaga

At least I'm not getting the Help Select-Xml now.

Add-Computer_2020-03-23_19-48-58

MaximoTrinidad commented 4 years ago

@anmenaga

Ah! No luck!

I just did an Update-Help -Force and the issue came back. Sorry!

Add-Computer2_2020-03-23_19-48-58

joeyaiello commented 4 years ago

Just did a little investigation: it looks like this is a symptom of the fact that you can't run Add-Computer from 7.x due to it existing in the system32/WinPS instance of MS.PS.Management. @anmenaga kinda fixed this where "first one wins" with cmdlets like ConvertFrom-String in MS.PS.Utility, but I suspect that because MS.PS.Mgmt is being loaded at startup time, you can never load the one system32 one that has Add-Computer.

@teskemj (or anyone else in the thread): are you able to actually run Add-Computer at all from 7.x? I cannot, hence my conclusion above.

If that's the case, we should rename this to "Add-Computer won't run from WinPS Microsoft.PowerShell.Management"

MaximoTrinidad commented 4 years ago

This might answer your question.

cmdletIssue_01_2020-08-20_14-51-59

Definitely it should be tagged! This cmdlet won't work in PS7.

joeyaiello commented 3 years ago

I verified that this is working now in 7.1.0. If it's still failing for you on 7.1 or newer, please file a new issue.