PowerShell 教程

PowerShell 基础语法

  • 定义变量

$CondaDir = "conda"
  • 获取当前目录的路径

Get-Location
  • 切换目录

Set-Location directory
  • 拷贝文件

Copy-Item source destination
Copy-Item source1,source2,source3 destination  # 逗号分隔,没有空格!!
  • 删除文件

Remove-Item file
  • 定义数组

$Excluded = @("bld.bat", "build.sh", "meta.yaml")
  • 获得文件集合

Get-ChildItem -Path "."  # 当前路径下的所有文件
Get-ChildItem -Path "." -Exclude $Excluded  # 排除某些文件
Get-ChildItem -Path "." -Exclude $Excluded  | Remove-Item -Force -Recurse  # 对符合模式的文件(夹)递归删除

PowerShell 设置环境变量

  • 查看所有环境变量

ls env:
  • 搜索环境变量

ls env:NODE*
  • 查看单个环境变量

$env:NODE_ENV
  • 添加/更新环境变量

$env:NODE_ENV=development
  • 删除环境变量

del evn:NODE_ENV