powershell - 相当于 Powershell 中的 `type -a`

标签 powershell

我正在尝试培养我的 PowerShell 故障排除技能,并且希望找到一个与 bash 中type 类似的工具。

type的用法示例:

17:07 Mac Shell: Git/>$ type -a shell_session_save
shell_session_save is a function
shell_session_save () 
{ 
    if [ -n "$SHELL_SESSION_FILE" ]; then
        echo -n 'Saving session...';
        ( umask 077;
        echo 'echo Restored session: "$(date -r '$(date +%s)')"' >|"$SHELL_SESSION_FILE" );
        declare -F shell_session_save_user_state > /dev/null && shell_session_save_user_state;
        shell_session_history_allowed && shell_session_save_history;
        echo 'completed.';
    fi
}
17:07 Mac Shell: Git/>$ 

我只是想要一种在 PowerShell 的 CLI 中查看函数代码的简单方法。这本身可能吗?

感谢您的帮助。

最佳答案

它可以使用 Get-Command 来本地使用,如下所示:

Get-Command MyFunctionName -ShowCommandInfo

这是我手头上的一个名为 Get-OutputFilePath 的函数的输出:

Name          : Get-OutputFilePath
ModuleName    : 
Module        : @{Name=}
CommandType   : Function
Definition    : 
                [CmdletBinding()]
                Param(
                    [String]$Filter = "All Files (*.*)|*.*",
                    [String]$InitialDirectory,
                    [Parameter(ValueFromPipelineByPropertyName,ValueFromPipeline)]
                    [Alias('DefaultFileName')]
                    [String]$FullName,
                    [Switch]$Force)
                    BEGIN{
                        [void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
                    }
                    PROCESS{
                        If($FullName -match "\\.+$" -and !$InitialDirectory){$InitialDirectory = Split-Path $FullName;$FullName = Split-Path $FullName -Leaf}ElseIf(!$InitialDirectory){$InitialDirectory=[Environment]::GetFolderPath('Desktop')}
                        $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
                        $SaveFileDialog.initialDirectory = $InitialDirectory
                        Try{$SaveFileDialog.filter = $Filter}Catch{Throw $_;Break}
                        $SaveFileDialog.FileName = $FullName
                        $SaveFileDialog.OverwritePrompt = !$Force
                        If($SaveFileDialog.ShowDialog() -eq "OK"){$SaveFileDialog.FileName}
                    }

ParameterSets : {@{Name=__AllParameterSets; IsDefault=False; Parameters=System.Management.Automation.PSObject[]}}

关于powershell - 相当于 Powershell 中的 `type -a`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47275109/

相关文章:

windows - 像 ntlite 一样从 Windows 10 中删除组件

powershell - PowerShell字符串默认参数值未按预期运行

powershell - 在powershell中获取HTTP请求并容忍500个服务器错误

powershell - 运行docker redis实例无法访问redis

powershell - 如何在 Windows 10 上使用 Powershell 将 Google Colab 与本地 TensorFlow Jupyter 服务器结合使用?

powershell - 交换powershell : get-mailbox outside default scope

powershell - 如何确定执行函数的文件名

powershell - 2个整数参数调用函数时出错

powershell - 将setCaseSensitiveInfo递归应用于所有文件夹和子文件夹

powershell - Install-Module -Name newtonsoft.json - 在我关闭并重新打开 ISE 之前一直有效