这是我第一天学习powershell,所以如果这个问题很傻的话,请原谅我...
但是我正在看的教学视频显示老师输入 "get-command -type cmdlet "来演示如何获得所有可用的cmdlet和它们的定义列表。我得到了cmdlet,但我的powershell没有列出定义。我附上了屏幕截图来告诉你他和我的情况。我需要做什么改变来解决这个问题?
定义属性可能没有出现,因为PowerShell正在为你的显示格式化它。定义可能对你的控制台显示来说太长了,所以它将以'...'结束。
使用下面的内容来查看所有可用的成员属性。在此基础上,你可以选择你想看到的属性。
Get-Command -Type Cmdlet | Format-List -Property Name, Definition
如果你想看PowerShell代码,这可能会很有趣。
Get-Command -Type Function |
Where-Object { $_.Definition.Length -gt 0 } |
Select-Object -Property Name,Definition |
Format-List
查看所有可用的propety成员。
PS H:\> Get-Command -Type Cmdlet | Get-Member
TypeName: System.Management.Automation.CmdletInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ResolveParameter Method System.Management.Automation.ParameterMetadata ResolveParameter(string name)
ToString Method string ToString()
CommandType Property System.Management.Automation.CommandTypes CommandType {get;}
DefaultParameterSet Property string DefaultParameterSet {get;}
Definition Property string Definition {get;}
HelpFile Property string HelpFile {get;}
ImplementingType Property type ImplementingType {get;}
Module Property psmoduleinfo Module {get;}
ModuleName Property string ModuleName {get;}
Name Property string Name {get;}
Noun Property string Noun {get;}
Options Property System.Management.Automation.ScopedItemOptions Options {get;set;}
OutputType Property System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.PSTypeName] OutputType {get;}
Parameters Property System.Collections.Generic.Dictionary[string,System.Management.Automation.ParameterMetadata] Parameters {get;}
ParameterSets Property System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.CommandParameterSetInfo] ParameterSets...
PSSnapIn Property System.Management.Automation.PSSnapInInfo PSSnapIn {get;}
RemotingCapability Property System.Management.Automation.RemotingCapability RemotingCapability {get;}
Source Property string Source {get;}
Verb Property string Verb {get;}
Version Property version Version {get;}
Visibility Property System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
DLL ScriptProperty System.Object DLL {get=$this.ImplementingType.Assembly.Location;}
HelpUri ScriptProperty System.Object HelpUri {get=$oldProgressPreference = $ProgressPreference...
Cmdlets是用C#编写的。 它们是被编译的,如果你说的是看源代码的话,你通常不能看到定义。
命令 get-command -type cmdlet
不显示定义。也许你想看到的定义 get-command
? :)
要查看定义,可以使用两种方式之一,如果命令支持,可以简单的添加一个? -?
在命令后面获得帮助。例如
get-command -?
-?
相当于 --h
或 --help
在bash中,有些命令不支持taht,因为那是命令中的一个参数,比如在bash中。有些命令不支持taht,因为那是命令中的一个参数,比如在 if
命令。对于这些类型的命令,你可以使用。
get-help if
它将会向你显示帮助 if
或向你展示有类似名称的东西,你可以得到帮助。这方面的一个例子是 break
命令。break
不支持 -?
方法,所以你必须使用 get-help break
但它也不会出现在那里。相反,你会得到以下的输出。
Name Category Module Synopsis
---- -------- ------ --------
Disable-PSBreakpoint Cmdlet Microsoft.PowerShell.U... Disables the breakpoints in the current console.
Enable-PSBreakpoint Cmdlet Microsoft.PowerShell.U... Enables the breakpoints in the current console.
Get-PSBreakpoint Cmdlet Microsoft.PowerShell.U... Gets the breakpoints that are set in the curre...
Remove-PSBreakpoint Cmdlet Microsoft.PowerShell.U... Deletes breakpoints from the current console.
Set-PSBreakpoint Cmdlet Microsoft.PowerShell.U... Sets a breakpoint on a line, command, or varia...
about_Break HelpFile Describes a statement you can use to immediate...
你可以看到它的输出是 break
帮助文件的别名为 about_Break
. 所以如果我输入 get-help about_Break
它将向我显示帮助。
你也可以使用get-help来查找所有的 cmdlets
宛 get-command
与 get-help -type cmdlet
但如果你想检查,我建议你看看帮助得到帮助:)。
更多信息 (字面意思)。你可以找到更多关于某些cmdlets的信息,如果它是可用的,使用下面的四个命令之一。
To see the examples, type: "get-help <command name> -examples".
For more information, type: "get-help <command name> -detailed".
For technical information, type: "get-help <command name> -full".
For online help, type: "get-help <command name> -online"
例如 (没有双关语的意思), 你可以找到关于以下的帮助 get-help
使用。
get-help Get-Help -examples
get-help Get-Help -detailed
get-help Get-Help -full
get-help Get-Help -online
而开关将具有上述标准(例子、额外信息、技术信息和在线帮助,因为网上有更多的东西文档)。