[轉]Windows PowerShell的12項酷功能

導讀:
  作者: ,  出處:網絡整理, 責任編輯: 劉志坡,  2007-11-19 10:15
  PowerShell原來的開發代號是Monad,原計劃是用以替代Windows中的命令行工具,但是後來微軟說它只是技術上的擴充。使用PowerShell,管理員可以做任何在圖形界面下所做的事情……
  PowerShell原來的開發代號是Monad,原計劃是用以替代Windows中的命令行工具,但是後來微軟說它只是技術上的擴充。使用PowerShell,管理員可以做任何在圖形界面下所做的事情。Windows PowerShell 1.0可以運行在Windows XP SP2、Windows Server 2003和Windows Vista上。
  1. 內置Cmdlets (即commandlets)
  Windows PowerShell中的所有Cmdlets都允許這樣的動名詞:get-service, get-process, stop-service, get-wmiobject.
  2. 強大的通配符和操作對象
  要得到以w開頭的服務及其依賴服務只要輸入:
  PS> get-service w* | format-list DisplayName, DependentServices
  3. 在犯錯誤前測試命令
  Windows PowerShell 有意向獨特的功能:Whatif ,可以不執行命令就告訴你命令執行結果.如:
  PS> stop-service w3* -whatif
  4. 獲取副本
  PowerShell 可以開始和結束所有命令的副本,可以在腳本中輕易測試命令並同時保存.
  PS> Start-Transcript -Path c:demodfoshow.txt
  PS> Stop-Transcript
  5. 從命令行發佈Windows對話
  因爲Windows PowerShell位對象而優化,可以向.NET Framework一樣從命令行訪問COM對象,下列命令告訴你的Vista機器發表Windows Vista and PowerShell字串.
  PS> $spVoice = new-object -com SAPI.spvoice
  PS> $spVoice.Speak(Windows Vista and PowerShell)
  6. 使用Windows PowerShell訪問諸如Windows Media Player 11等的應用程序
  PS> $band = The Posies
  PS> $player = New-object -com wmplayer.ocx
  PS> $playlist = $player.mediacollection.getbyauthor($band)
  PS> $player.openPlayer($playlist.item(0).sourceurl)
  7. Windows PowerShell作爲命令行存儲計算器
  PowerShell可以完成基本的計算工作
  PS> 2*2
  不過,Windows PowerShell也可以快速解決存儲問題,例如,備份11GB的數據需要多少個700MB的CD.
  PS> 11gb/700mb
  那麼,需要多少個1000GB的存儲來備份每個320GB,共425個的Vista桌面呢?
  PS >(320gb*425)/1000GB
  8. PowerShell 用作日曆計算
  計算多少天到新年:
  PS> ([DateTime]1/1/2007 -[datetime]::now).days
  共2頁。 12:

本文轉自
http://winsystem.ctocio.com.cn/serveradmin/241/7670241.shtml
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章