基本cmd命令
md qq创建文件夹cd ..cd www返回上级目录 进入目录d:进入d盘rd qq删除空文件夹del 1.txt /q删除文件或目录 不确认ren qq vv重命名type 1.txt读取并显示ipconfig查看本地ipping www.baidu.com查看ippause暂停upx 1.exe压缩exe文件wget下载文件curl提交文件7z a 1.zip yoby_tt压缩7zset 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/falseTest-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" getirm "https://jsonplaceholder.typicode.com/users" -Post '{"name":"测试","age":25}' postiwr "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 wingetpowershell7.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\goscoop使用
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
REMwindows后台运行
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 更新时间:2026-02-19 16:09