PowerShell Memo

  • 1422
  • 0
  • 2016-05-05

此篇是邊做邊學使用 PowerShell 指令的紀錄文。

紀錄

新增檔案

PowerShell New-Item D:\PowerShellSample\AnEmptyFile.txt -ItemType File

附加內容

PowerShell Set-Content D:\PowerShellSample\AnEmptyFile.txt -Encoding UTF8 -Value 測試新增一段文字

取代部分內容 (純文字)

PowerShell -Command "(Get-Content D:\PowerShellSample\File.txt) -replace '舊內容', '新內容' | Set-Content -Encoding UTF8 D:PowerShellSample\File.txt"

取代部分內容 (符號一併取代)

PowerShell -Command "(Get-Content D:\PowerShellSample\File.txt) -replace '\(舊內容\)', '新內容' | Set-Content -Encoding UTF8 D:PowerShellSample\File.txt"

複製檔案

PowerShell Copy-Item -Path "D:\PowerShellSample\**" -Destination "D:\PowerShellTest" -Force -Recurse

刪除檔案

PowerShell Remove-Item -Path "D:\PowerShellTest\**" -Force -Recurse

Sleep (秒)

PowerShell Start-Sleep -s 10

Sleep (毫秒)

PowerShell Start-Sleep -m 500