Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Windows 10 PowerShell 進階任務 15 選:日期時間管理、檔案驗證重命名移動、服務控制、Apps 強制刷新

編輯:Win10 系統應用技巧

Windows PowerShell 是命令列外殼與腳本環境,未來可能取代 CMD。Win10 中許多用戶對 PowerShell 陌生,介紹 15 個常用進階任務。

15 項常用 PowerShell 進階任務:

  1. 開啟 PowerShell 環境: 搜尋「PowerShell」以管理員身分運行,或搜尋後 Ctrl+Shift+Enter;
  2. 設定日期時間: Set-Date -date "2016-12-01 8:30 AM";
  3. 調整日期時間: Set-Date (Get-Date).AddDays(2),可用 AddHours/AddMinutes/AddSeconds;
  4. 驗證檔案/資料夾: Test-Path c:\PowerShell.xlsx 回傳 True/False,支援萬用字元 Test-Path c:\*.xlsx;
  5. 重命名檔案/資料夾: Rename-Item c:\PowerShell.xlsx New_PowerShell.xlsx;
  6. 移動檔案/資料夾: Move-Item c:\PowerShell.xlsx d:\PowerShell.xlsx,配合萬用字元批次移動 Move-Item c:\*.xls d:\excel\;
  7. 開啟程式: Invoke-Item c:\Windows\System32\notepad.exe,PATH 內程式可直接用名稱 notepad;
  8. 用預設程式開啟檔案: Invoke-Item c:\Sysgeek\Hello.txt 會用關聯預設應用;
  9. 批次開啟檔案: Invoke-Item c:\Sysgeek\*.txt;
  10. 讀取文字檔: Get-Content c:\Sysgeek\Hello.txt,預覽首行 Get-Content ... -totalcount 1;
  11. 新增文字內容: Add-Content c:\Sysgeek\Hello.txt "by 海猴子" (追加至檔尾);
  12. 統計文字檔: Get-Content c:\Sysgeek\Hello.txt | Measure-Object (行數、字數等);
  13. 服務狀態統計: Get-Service 列出所有服務,Get-Service | Where-Object {$_.status -eq "stopped"} 統計已停止服務;
  14. 重啟服務: Restart-Service Dnscache 或 Restart-Service -displayname "DNS Client";
  15. 更改服務啟動類型: Set-Service Dnscache -startuptype "manual",可用 automatic/disabled。

強制刷新 Win10 Apps: Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}。PowerShell 亦可用於移除 Win10 內建應用。文章實用,建議收藏備查。

Copyright © Windows教程網 All Rights Reserved