PowerShell運維人員常用命令收集整理
檢視類:
檢視powershell版本 $PSVersionTable
檢視作業系統版本資訊 Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName . | Select-Object -Property Build*,OSType,ServicePack*
檢視部分組策略 gpresult /Z
檢視部分組策略(需要匯出到檔案) secedit /export /cfg c:\sec_result
檢視服務 Get-Service
檢視執行中服務 Get-Service | Where-Object {$_.Status -eq 'Running'}
檢視IP ipconfig /all或者Get-NetipConfiguration
檢視程序 Get-Process
檢視已安裝補丁 Get-WmiObject -Class Win32_QuickFixEngineering或者wmic qfe list
檢視使用Windows Installer安裝的程式 Get-WmiObject -Class Win32_Product | Format-Wide -Column 1
檢視CPU相關資訊 get-wmiobject win32_processor
檢視CPU使用率2008/2012通用 Get-WmiObject win32_processor | select SystemName, LoadPercentage
檢視CPU使用率排名前20 Get-Counter -ComputerName localhost '\Process(*)\% Processor Time' | Select-Object -ExpandProperty countersamples | Select-Object -Property instancename, cookedvalue| Sort-Object -Property cookedvalue -Descending| Select-Object -First 20| ft InstanceName,@{L='CPU';E={($_.Cookedvalue/100).toString('P')}} -AutoSize
檢視系統版本/序列號 gwmi win32_OperatingSystem
檢視總記憶體 Get-WmiObject win32_OperatingSystem TotalVisibleMemorySize
檢視總記憶體(單位GB) gwmi Win32_PhysicalMemory | %{$sum = 0} { $sum += $_.Capacity } {Write-Host ($sum / 1GB) "GB"}
檢視空閒記憶體 Get-WmiObject win32_OperatingSystem FreePhysicalMemory
檢視磁碟總空間(單位MB) Get-WMIObject Win32_LogicalDisk |Where-Object{$_.Size}|Foreach-Object { 'Disk {0} has {1:0.0} MB totalspace' -f $_.Caption, ($_.Size / 1MB) }
檢視防火牆狀態 netsh advfirewall show currentprofile
檢視BIOS資訊 Get-WMIObject -Class Win32_BIOS
檢視主機板資訊 Get-WMIObject -Class Win32_Baseboard
檢視邏輯磁碟資訊 Get-WMIObject -Class Win32_LogicalDisk
檢視物理磁碟資訊 Get-WMIObject -Class Win32_DiskDrive
檢視桌面設定(屏保是否設定) Get-CimInstance -ClassName Win32_Desktop
檢視一個資料夾內的檔案及目錄 Get-ChildItem -Path C:\ -Force
管理類:
重啟伺服器 Restart-Computer 或者 Restart-Computer -Force強制重啟
關閉伺服器 stop-computer
停止spooler服務 Stop-Service -Name spooler
啟動spooler服務 Start-Service -Name spooler
重啟spooler服務 Restart-Service -Name spooler
停止某個程序 stop-process -id 2792
鎖定伺服器 rundll32.exe user32.dll,LockWorkStation
新增登錄檔項 New-Item -Path hkcu:\software_DeleteMe
刪除登錄檔項 Remove-Item -Path hkcu:\Software_DeleteMe