IT 運維常面臨「跨平台、跨廠商、跨層級」技能要求,但預算有限無法開發專屬管理軟體。PowerShell 並非取代 CMD,而是提供 **物件導向管線、豐富 .NET 整合、遠端執行、腳本模組化** 的管理自動化引擎,專為 **系統管理員 (非開發人員)** 設計,以極低門檻解決批量、遠端、重複性任務。
$servers = Get-Content C:\List\servers.txt
$results = foreach ($s in $servers) {
$disk = Get-WmiObject Win32_LogicalDisk -ComputerName $s -Filter "DeviceID='C:'" -ErrorAction SilentlyContinue
$mem = Get-WmiObject Win32_ComputerSystem -ComputerName $s -ErrorAction SilentlyContinue
if ($disk -and $mem) {
[pscustomobject]@{
Server = $s
FreeGB = [math]::Round($disk.FreeSpace/1GB,2)
TotalRAM_GB = [math]::Round($mem.TotalPhysicalMemory/1GB,2)
Eligible = ($disk.FreeSpace -ge 4GB -and $mem.TotalPhysicalMemory -ge 1GB)
}
}
}
$results | Export-Csv C:\Reports\Eligibility.csv -NoTypeInformation -Encoding UTF8
$eligible = Import-Csv C:\Reports\Eligibility.csv | Where-Object {$_.Eligible -eq 'True'}
foreach ($row in $eligible) {
Invoke-Command -ComputerName $row.Server -ScriptBlock {
& "\\Deploy\Office2007\setup.exe" /adminfile "\\Deploy\Office2007\config.msp" /quiet /norestart
} -Credential (Get-Credential) -ErrorAction Continue
}
$critical = @('wuauserv','bits','w3svc','MSSQLSERVER')
$servers = Get-Content C:\List\servers.txt
foreach ($s in $servers) {
foreach ($svc in $critical) {
$status = Get-Service -Name $svc -ComputerName $s -ErrorAction SilentlyContinue
if ($status -and $status.Status -ne 'Running') {
Write-Warning "[$s] $svc 狀態: $($status.Status) → 嘗試啟動"
Start-Service -Name $svc -ComputerName $s -ErrorAction SilentlyContinue
}
}
}
PowerShell 將「管理員會寫腳本」從願景變為現實:無需編譯、無需部署代理、物件管線直觀、遠端原生、社群資源豐富。Server 2008 內建 PowerShell 1.0 (R2 內建 2.0),配合 WinRM 2.0 即可開啟自動化運維新紀元。建議每位網管投入 20 小時系統學習,終身受益。
Windows 2000 全面優化 (二):滑鼠採樣率提升、關閉系統音效、清除事件日誌、移除 POSIX 子系統
隱藏 Windows Server 2008 避免安全威脅三大戰術
Windows 2000 磁碟管理概述:動態儲存、本地/遠端管理、簡化介面、磁碟路徑掛載、基本/動態磁碟差異
Windows Server 2003 SMTP 服務本機網域設定完整教學
老電腦也能跑 Win2K:終端服務讓 32MB 記憶體機器流暢體驗 Windows 2000
Paragon Partition Manager 實現 NTFS 轉 FAT32 無損轉換並保留中文檔名
Windows Server 2003 建立開機磁碟片完整教學:有/無 2003 環境雙重情境、SCSI/IDE 開機參數配置