基本cmd命令

  • md qq 创建文件夹
  • cd .. cd www 返回上级目录 进入目录
  • d: 进入d盘
  • rd qq 删除空文件夹
  • del 1.txt /q 删除文件或目录 不确认
  • ren qq vv 重命名
  • type 1.txt 读取并显示
  • ipconfig 查看本地ip
  • ping www.baidu.com 查看ip
  • pause 暂停
  • upx 1.exe 压缩exe文件
  • wget 下载文件
  • curl 提交文件
  • 7z a 1.zip yoby_tt 压缩7z
  • set CGO_ENABLED=1 导入变量
  • bcdedit /set hypervisorlaunchtype auto 安卓子系统启用

    pwsh,支持win/mac/linux

    注释 # 多行<# 注释 #>
    Get-Alias 别名大全
    ls 或 dir 列出文件
    cd 进入目录
    pwd 当前目录
    md 或 mkdir 新建文件夹
    rm 删除文件
    rm -rf 删除非空文件夹
    cls 或 ctrl+L 清屏
    $a+$b 变量
    if($a>1){}else{} 条件
    for ($i=5; $i -ge 1; $i–) {
    Write-Host “$i “ -n #输出在同一样
    Start-Sleep -s 1
    }
    $colors = @(“Red”, “Green”, “Blue”)
    foreach ($color in $colors) {
    Write-Output “颜色:$color”
    }
    function Square($x) { return $x * $x }
    Square(5)
    try {
    Get-Item “C:\NotExist.txt”
    } catch {
    Write-Output “找不到文件”
    }
    dir ; echo “完成”
    dir && echo “成功”
    dir || echo “失败”
    echo 1,2,3 | ForEach-Object { “元素:$_” }
    read-host -p "按回车键继续执行下一步" 暂停
    ni -f 2.txt 创建文件,覆盖,不要参数不覆盖
    ni -i d qqqq 创建目录
    Write-Host “✅ 操作成功!” -f green
    Write-Host “⚠️ 文件已存在” -f Yellow
    Write-Host “❌ 执行失败!” -f red
    Write-Host “ℹ️ 请输入正确路径” -f blue
    Write-Host “苹果” “香蕉” “橙子” -s “, “ 分隔符
    cp 1.txt 2.txt 复制文件
    cp a b -rf 递归复制 \文件夹包含本身,不加只是内容
    mv a b -f 移动文件夹
    (gc 11.txt).count 读取文件并统计行数
    gc 11.txt -ta 1 读取1行 默认是数组类型
    (gc 11.txt)[0] 第一行内容
    (gc 11.txt -ra).gettype() 数据类型,这是返回字符串类型
    set-content 22.txt oo 写入内容覆盖写入
    ac 22.txt 90 -e utf8 追加
    ac 22.txt $arr 写入数组
    $(get-date) 年月日时间变量
    $env:COMPUTERNAME 主机名
    $env:USERNAME 用户名

ren 22.txt 99.txt 重命名
test-path 11.txt 路径是否存在
test-path o -pathtype c 判断文件夹 l是文件
$c=gc 11.txt -ra
$nc = $c -replace “中国”,”xx” //替换
set-content 11.txt $nc
(gi 11.txt) name 文件名 fullname 完整路径
extension 扩展名包含点 length 长度

Get-Process -Name notepad | Stop-Process -Force 停止进程
Get-Process -Name notepad -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue 不提示
Stop-Process -Name chrome* -Force停止开头进程
Start-Process notepad 启动程序,第三方完整路径
Start-Process powershell -Verb RunAs 管理员身份打开
Start-Process "https://learn.microsoft.com" 打开网址
Start-Process notepad 11.txt 打开内容
Start-Process -FilePath "C:\script.bat" -WindowStyle Hidden 隐藏窗口 -ErrorAction SilentlyContinue 忽视错误

Test-Connection github.com -count 1 -quiet 判断网络是否连通返回 true/false
Test-Connection 192.168.1.1 -Count 10 ping简化版
-TimeoutSeconds 2 超时2秒

Get-NetIPAddress -AddressFamily IPv4 | Select-Object InterfaceAlias, IPAddress, PrefixLength, PrefixOrigin ipv4信息
Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin DHCP 动态ip信息

irm "https://example.com/remote-script.ps1" | iex 执行脚本经典写法
$user = irm "https://api.github.com/users/octocat" get
irm "https://jsonplaceholder.typicode.com/users" -Post '{"name":"测试","age":25}' post
iwr "https://avatars.githubusercontent.com/u/583231?v=4" -OutFile "avatar.png" 下载二进制

数据类型 “abc” 123 3.14 $true $false
$arr = @(1, 2, 3) 数组
$h = @{Name=”Tom”; Age=30} map类型
等于-eq 不等于-ne 小于-lt 小于等于-le 大于-gt 大于等于-ge

winget使用

  • winget search qq 查找
  • winget show qq 显示信息
  • winget upgrade 查询全部更新
  • winget upgrade --all 更新所有
  • winget upgrade Microsoft.PowerToys 更新
  • winget uninstall qq 卸载
  • winget source list 显示当前源
  • winget source remove winget 移除默认源 add winget添加
  • winget source reset winget 重置官方
  • winget install --id Microsoft.PowerShell --source winget powershell7.x安装
  • winget upgrade Microsoft.PowerShell 升级

    常用软件

    winget install Microsoft.Edit  DevToys-app.DevToys  Microsoft.WindowsTerminal 
    winget install Tencent.WeChat Tencent.WeixinDevTools Tencent.TencentVideo Tencent.QQ  Tencent.QQMusic Tencent.QQPlayer Tencent.Yuanbao
    winget install iQIYI.iQIYI
    winget install ByteDance.Doubao ByteDance.JianyingPro ByteDance.Trae.CN
    winget install iFlytek.iFlyIME
    winget install  Youku.Youku
    winget install  7zip.7zip M2Team.NanaZip
    winget install Python.Python.2 Python.Python.3.9

    常用变量

### path环境变量
C:\app\bin
C:\app\git\mingw64\bin
### 变量
PUB_HOSTED_URL=https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
CHROME_EXECUTABLE = C:\Program Files (x86)\Microsoft\Edge\Application
JAVA_HOME= C:\app\green\goland\jbr
ANDROID_HOME = C:\app\SDK

GOPROXY = https://goproxy.cn,direct
GOROOT=C:\Program Files\Go
GOPATH = C:\app\www\go

scoop使用

 scoop info go 查看  
 scoop install go
 scoop uninstall go
 scoop list 列出已安装
 scoop search go 搜索
 scoop which go 路径
 scoop status 检查更新
scoop update go 更新  * 代表全部
scoop reinstall go 重装
 scoop update 更新自己
 scoop bucket list 查看仓库
 scoop bucket add extras 添加仓库 main

启动隐藏窗口

@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
REM

windows后台运行

dim objShell 
set objShell=wscript.createObject("WScript.Shell") 
dim path
path = createobject("Scripting.FileSystemObject").GetFolder(".").Path
msgbox "启动程序进程成功"
iReturnCode=objShell.Run(path&"\hello.exe",0,TRUE)
作者:Yoby  创建时间:2020-07-22 21:51
最后编辑:Yoby  更新时间:2026-02-19 16:09
上一篇:
下一篇: