Powershell 2:如何消除重复的帮助条目?

我经常打电话如:

get-help <some-command> 

在Powershell 2中。对于这些命令中的很多但不是全部,我没有显示帮助条目的内容。 相反,我得到重复,只有帮助对象本身显示:

 [PS2]> get-help remove-distributiongroup | more Name Category Synopsis ---- -------- -------- Remove-DistributionGroup Cmdlet Use the Remove-DistributionGroup... Remove-DistributionGroup Cmdlet Use the Remove-DistributionGroup... 

作为一个完整的PS新手,我通过做类似下面的事情来解决这个问题:

 [PS2]> $var = get-help remove-distributiongroup [PS2]> $var[0] | get-member ... Output ... [PS2]> $var[0].Parameters |more ... Part of the documentation ... [PS2]> $var[0].Synopsis |more ... Another part of the documentation ... 

几个问题。

  • 我的Windowspipe理员同事是否知道如何删除重复条目? 我只是一个Unix的家伙。
  • 如果没有,有没有更容易的方法来获得我所需要的,而不是我上面提到的那些复杂的黑客?

谢谢!

[UPDATE [:

试过PK的build议,但可悲的是没有奏效。 下面是通过select -unique传送的输出:

 Name Category Synopsis ---- -------- -------- Get-DistributionGroup Cmdlet Use the Get-DistributionGroup cm... 

这可能是由重复PS Snapins加载引起的。 如果您在Exchange命令行pipe理程序中,然后加载Exchange 2010pipe理pipe理单元(可能在脚本中?),您将看到这些重复的get-help响应。 运行EMS运行get-pssnapin并检查E2010pipe理单元。 如果有,请使用remove-pssnapin将其卸载。

有关更多信息,请参阅“ Get-Help生成重复主题 ”。

  1. 从来没有在PowerShell中使用“更多”。 更多使用默认的格式化程序(哪个格式表也使用。)
  2. 如果使用了Format-list命令行开关,则会发现get-help返回一个带有“pssnapin”属性或“modulename”属性的对象。

默认格式化程序可能会误导,但格式化列表或使用get-member命令行程序将列出所有的属性。 我敢打赌,如果你重新运行你的命令,你会得到一个用户格式:[PS2]> get-help remove-distributiongroup | select名称,简介,模块名称,pssnapin

 Name Category Synopsis PsSnapin ---- -------- -------- -------- Remove-DistributionGroup Cmdlet Use the Remove-DistributionGroup... ASnapin Remove-DistributionGroup Cmdlet Use the Remove-DistributionGroup... AnotherSnapin 

(上面的输出不是真实的)但是它的核心是你将能够看到哪个模块具有重复的命令。

这真的不是重复的,因为你可以像Asnapin \ Remove-DistributionGroup或AnotherSnapin \ Remove-DistributionGroup那样调用每个命令来使用其他版本:)

我不知道你为什么得到重复。 我不能重现这个问题,但我确实有一个想法,就是如何以稍微优雅的方式解决它。

 get-help remove-distributiongroup | select -unique 

那样有用吗?

这是什么回报?

 Test-Path -path "$pshome\Help.format.ps1xml" 

该文件包含由Get-Help返回的MamlCommandHelpInfo对象的格式化视图。

我遇到了一些情况,那些试图使用Exchange 2010,2013运行Get-Help命令的人获取重复的cmdlet列表,而不是实际的帮助内容。 这很可能来自运行加载Microsoft.Exchange.Management.PowerShell.E2010的PSSnapin的脚本。 下面是你可以做什么来删除这个特定的,也许是其他重复的条目:

为了快速绕过这个问题:

只要运行: Get-Help <cmdlet name> -Category 'Function' -full

例:

Get-Help Get-MailboxFolderPermission -Category 'Function' -full

否则,要获取更多信息并解决问题:

该命令显示该命令的帮助条目相关数据,并将返回我们稍后需要的pipe理单元名称:

Get-Help Get-Mailbox | Select Name,PSSnapIn

该命令显示命令的完整命令相关数据:

Get-Command Get-Mailbox | Select Name,CommandType

检查此输出中的CommandType。 您可能会看到其中一个的命令types被列为Cmdlet,另一个被列为function。 这很可能是因为在某些时候,Exchangepipe理pipe理单元被手动添加或通过运行的脚本添加。 由于Exchangepipe理shell根据需要设置了shell,因此pipe理单元不应该被加载,因此应该将其删除。

使用此命令删除pipe理单元:

Remove-PSSnapin -Name <name of snapin from 1st command above>

例:

Remove-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010

这将删除pipe理单元并保留启动Exchange命令行pipe理程序时加载的单个function。

下面的脚本正在为我工​​作,删除Get-Help中的重复条目:

 $sys32Help = Get-ChildItem -Path "C:\Windows\System32\WindowsPowerShell\v1.0\en-US\" -Filter {*help*} $sys32ModHelp = Get-ChildItem -Path "C:\Windows\System32\WindowsPowerShell\v1.0\Modules" -Filter {*help*} -Recurse -File $compare = Compare-Object -ReferenceObject $sys32Help -DifferenceObject $sys32ModHelp -Property name -IncludeEqual $compEQ = $compare | where sideIndicator -eq == | Select name | %{ $_.Name } $sys32ModHelp | ?{ $_.Name -in $compEQ } | %{ Remove-Item -Path $_.FullName -Force -ErrorAction SilentlyContinue}