Windows管理員常用的25個PowerShell命令

來源:互聯網
上載者:User

for Windows 2008

 

 

儘管Windows PowerShell已經出現一段時間了,習慣命令列的管理員可能對瞭解PowerShell功能的基礎高度興趣。

  下面我們看看能由Windows PowerShell完成的最常見的25個任務。不止是這些任務很簡單,顯示語句的命令架構和其他PowerShell命令也很簡單。掌握好這些基本命令是成為PowerShell專家的必經之路。

 

  入門層級

 

  1. 像檔案系統那樣操作Windows Registry——cd hkcu:

 

  2. 在檔案裡遞迴地搜尋某個字串——dir –r | select string "searchforthis"
  
  3. 使用記憶體找到五個進程——ps | sort –p ws | select –last 5

 

  4. 迴圈(停止,然後重啟)一個服務,如DHCP——Restart-Service DHCP

 

  5. 在檔案夾裡列出所有條目——Get-ChildItem – Force

 

  6. 遞迴一系列的目錄或檔案夾——Get-ChildItem –Force c:/directory –Recurse

 

  7. 在目錄裡移除所有檔案而不需要單個移除——Remove-Item C:/tobedeleted –Recurse

 

  8. 重啟當前電腦——(Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)

 

  收集資訊

 

  9. 擷取電腦群組成或模型資訊——Get-WmiObject -Class Win32_ComputerSystem

 

  10. 擷取當前電腦的BIOS資訊——Get-WmiObject -Class Win32_BIOS -ComputerName .

 

  11. 列出所安裝的修複程式(如QFE或Windows Update檔案)——Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName .

 

  12. 擷取當前登入電腦的使用者的使用者名稱—— Get-WmiObject -Class Win32_ComputerSystem -Property UserName -ComputerName .

 

  13. 擷取當前電腦所安裝的應用的名字——Get-WmiObject -Class Win32_Product -ComputerName . | Format-Wide -Column 1

 

  14. 擷取分配給當前電腦的IP地址——Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Format-Table -Property IPAddress

 

  15. 擷取當前機器詳細的IP配置報道——Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*

 

  16. 找到當前電腦上使用DHCP啟用的網路卡——Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=true" -ComputerName .

 

  17. 在當前電腦上的所有網路介面卡上啟用DHCP——Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=true -ComputerName . | ForEach-Object -Process {$_.EnableDHCP()}

 

  軟體管理

 

  18. 在遠端電腦上安裝MSI包——(Get-WMIObject -ComputerName TARGETMACHINE -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install(//MACHINEWHEREMSIRESIDES/path/package.msi)

 

  19. 使用基於MSI的應用升級包升級所安裝的應用——(Get-WmiObject -Class Win32_Product -ComputerName . -Filter "Name='name_of_app_to_be_upgraded'").Upgrade(//MACHINEWHEREMSIRESIDES/path/upgrade_package.msi)

 

  20. 從當前電腦移除MSI包——(Get-WmiObject -Class Win32_Product -Filter "Name='product_to_remove'" -ComputerName . ).Uninstall()

 

  機器管理

 

  21. 一分鐘後遠程關閉另一台機器——Start-Sleep 60; Restart-Computer –Force –ComputerName TARGETMACHINE

 

  22. 添加印表機——(New-Object -ComObject WScript.Network).AddWindowsPrinterConnection(//printerserver/hplaser3)

 

  23. 移除印表機——(New-Object -ComObject WScript.Network).RemovePrinterConnection("//printerserver/hplaser3 ")

 

  24. 進入PowerShell會話——invoke-command -computername machine1, machine2 -filepath c:/Script/script.ps1

 

 

轉載於:

http://www.vmsky.com/tech/Microsoft/win2008/2010/01/08/6686.html

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.