windwos terminal 管理员提权

使用 pwsh 编写工具

前提

分为三个步骤,只需要不断重复组合即可

  1. 理解设计规则
  2. 使用帮助手册 get-help
  3. 结合管道命令组合使用 |
  4. 查看方法属性 get-member get-command
  5. 调用类方法 ([command]).<method>

设计规则

  1. 查看属性
  2. 筛选属性
  3. 格式化输出

常用类型分为:Alias、Cmdlet、Function、Application、Script…..(共9个,详见下方超链)

CommandType枚举值

Alias 1 Aliases create a name that refers to other command types
All 511 All possible command types.
Application 32 Any existing application (can be console or GUI).
Cmdlet 8 A cmdlet.
Configuration 256 A Configuration
ExternalScript 16 An MSH script (*.ps1 file)
Filter 4 Script filters that are defined by a script block.
Function 2 Script functions that are defined by a script block
Script 64 A script that is built into the runspace configuration
get-command <command>

# 例子

❯❯ pwsh-demo  01:01 Get-Command vim

# 输出

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     vim.exe                                            0.0.0.0    D:\\.data\\Scoop\\shims\\vim.exe