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

Windows 7 PowerShell 入門指南:啟動、常用指令、進程管理、別名技巧

編輯:Windows 7 系統介紹

Windows 7 內建 PowerShell 2.0,提供強大的命令列殼層與腳本語言,支援 .NET 物件管線、遠端管理、系統自動化。本文介紹啟動方式、核心指令探索、進程/服務管理、別名建立等實用技巧。

啟動 PowerShell

  • 開始 → 搜尋框輸入 PowerShell → 選「Windows PowerShell」(命令列模式)或「Windows PowerShell ISE」(圖形化整合腳本環境)
  • CMD 中輸入 powershell 切換
  • Win+R → powershell

探索可用指令

Get-Command          # 列出所有 Cmdlet、Function、Alias、Application
Get-Command *service* # 關鍵字篩選
Get-Help Get-Process # 查看指令詳細用法(含語法、參數、範例、備註)
Get-Help Get-Process -Examples # 僅看範例
Update-Help          # 下載最新說明內容(需網路)

進程管理實戰

# 列出所有進程
Get-Process

# 依 CPU 使用率排序前 10
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10

# 依 ID 結束進程
Stop-Process -Id 1234

# 依名稱結束進程(支援萬用字元)
Stop-Process -Name "notepad*"

# 取得進程詳細資訊
Get-Process -Id 1234 | Format-List *

服務管理

Get-Service                    # 列出所有服務
Get-Service wuauserv           # 查詢特定服務
Start-Service wuauserv         # 啟動服務
Stop-Service wuauserv          # 停止服務
Set-Service wuauserv -StartupType Automatic # 設定啟動類型
(Get-Service wuauserv).Status  # 取得狀態屬性

別名技巧:自訂指令縮寫

# 建立別名:gp 代表 Get-Process
Set-Alias gp Get-Process
gp  # 直接使用

# 建立別名:np 代表 notepad
Set-Alias np notepad.exe
np  # 快速開啟記事本

# 查看所有別名
Get-Alias

# 匯出別名清單
Export-Alias alias_backup.txt

# 讓別名永久生效:加入 $PROFILE 腳本
notepad $PROFILE
# 在開啟的記事本加入 Set-Alias gp Get-Process 等行,存檔關閉
# 重新開啟 PowerShell 即自動載入

登錄檔操作

# 瀏覽登錄檔如同檔案系統
Set-Location HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion
Get-ChildItem
Get-ItemProperty .\Run

# 新增登錄檔值
New-ItemProperty -Path HKCU:\Software\MyApp -Name "Setting" -Value "Enabled" -PropertyType String

網路相關

Test-Connection google.com        # Ping
Get-NetIPConfiguration            # 取得 IP 設定 (需 Win8+/PS 5.1+)
Invoke-WebRequest https://api.github.com # HTTP 請求

學習資源

PowerShell 以物件管線取代文字管線,是 Windows 系統管理自動化的核心利器。善用 Get-Help 與 Get-Command 自我探索,比背指令更有效。
Copyright © Windows教程網 All Rights Reserved