2012-06-01 109 views
15

如何确定给定cmdlet的模块,以便从覆盖该cmdlet的函数直接调用该模块。如何找到给定cmdlet的模块?

例如,我该如何发现Start-Transcript存在于Microsoft.Powershell.Host中?

get-module Start-Transcript 

不会产生任何

更新下面的答案。 这是输出:

PS C:\Windows> get-command -type cmdlet start-transcript | fl * 


HelpUri    : http://go.microsoft.com/fwlink/?LinkID=113408 
DLL     : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.ConsoleHost\1.0.0.0__31bf3856ad364e35\Microsoft 
         .PowerShell.ConsoleHost.dll 
Verb    : Start 
Noun    : Transcript 
HelpFile   : Microsoft.PowerShell.ConsoleHost.dll-Help.xml 
PSSnapIn   : Microsoft.PowerShell.Host 
ImplementingType : Microsoft.PowerShell.Commands.StartTranscriptCommand 
Definition   : Start-Transcript [[-Path] <String>] [-Append] [-Force] [-NoClobber] [-Verbose] [-Debug] [-ErrorAc 
         tion <ActionPreference>] [-WarningAction <ActionPreference>] [-ErrorVariable <String>] [-WarningV 
         ariable <String>] [-OutVariable <String>] [-OutBuffer <Int32>] [-WhatIf] [-Confirm] 

DefaultParameterSet : 
OutputType   : {} 
Name    : Start-Transcript 
CommandType   : Cmdlet 
Visibility   : Public 
ModuleName   : Microsoft.PowerShell.Host <------------ HERE IT IS 
Module    : 
Parameters   : {[Path, System.Management.Automation.ParameterMetadata], [Append, System.Management.Automation.Pa 
         rameterMetadata], [Force, System.Management.Automation.ParameterMetadata], [NoClobber, System.Man 
         agement.Automation.ParameterMetadata]...} 
ParameterSets  : {[[-Path] <String>] [-Append] [-Force] [-NoClobber] [-Verbose] [-Debug] [-ErrorAction <ActionPref 
         erence>] [-WarningAction <ActionPreference>] [-ErrorVariable <String>] [-WarningVariable <String> 
         ] [-OutVariable <String>] [-OutBuffer <Int32>] [-WhatIf] [-Confirm]} 

回答

8

使用

get-command start-transcript | fl *

找到有关命令的信息。

+0

有一个ModuleName属性不会显示在get-command的默认表中。 (查找ModuleName:Microsoft.PowerShell.Host) – user1324792

+1

这会更好:get-command -type cmdlet start-transcript |选择ModuleName – user1324792

+5

更简洁的版本:'(Get-Command Start-Transcript).ModuleName' –

2

PowerShell中有几个选项。为了缩小结果的具体信息您正在寻找 - 以下方法之一,可以用:

(Get-Command -Name Start-Transcript).ModuleName 

Get-Command -Name Start-Transcript | Select-Object -Property ModuleName 

Get-Command -Name Start-Transcript | Format-List -Property ModuleName 

注:

通常认为使用不带别名的完整cmdlet名称(如fl,ft,select et c。)每当您在PowerShell脚本中使用它或开发自定义的PowerShell模块时。它增加了您的代码可读性。

相关问题