Powershell

一.开启 powershell

  1. win + R 输入 powershell

  2. 管理员身份运行 Ctrl + Shift + Enter

PowerShell 升级和 Windows Terminal 配置

  1. 查看 PowerShell 当前版本
$PSVersionTable
  1. 更新 PowerShell

添加中科大镜像源

winget source add --name winget --arg https://mirrors.ustc.edu.cn/winget-source
winget search PowerShell # 查询可用的 PowerShell 包
  1. 安装(微软发布的 PowerShell)
winget install --id Microsoft.PowerShell -e
  1. 打开 Windows Terminal 的 settings.json 并修改配置(示例,替换为你的 GUID)
{
  "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
  "profiles": {
    "list": [
      {
        "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
        "name": "PowerShell",
        "source": "Windows.Terminal.PowershellCore",
        "hidden": false
      }
    ]
  }
}

二. 文件相关命令

  1. 进入文件夹
cd .\
  1. 返回上级目录
cd ..
  1. 创建目录 / 文件
mkdir .\NewFolder

ni .\file.txt -ItemType File
  1. 删除文件或目录
rm .\file.txt
  1. 移动 / 重命名
mv .\source.txt .\dest.txt
  1. 使用 VS Code 打开当前目录
code .
  1. 清空回收站(无提示)
Clear-RecycleBin -Force -Confirm:$false

三. 常用命令

环境变量

  1. 显示环境变量
gci env:
  1. 设置(追加)环境变量路径
$env:Path += ";C:\你的\路径"

网络配置

  1. 显示本机 IP
ipconfig
  1. 测试网络连通性
ping <IP 或 主机名>
  1. 关闭防火墙(谨慎)
netsh advfirewall set allprofiles state off
  1. 显示网络统计信息
netstat -an
  1. 显示本地路由表
route print
  1. 显示/查询防火墙规则
Get-NetFirewallRule