目前分類:PowerShell (163)

瀏覽方式: 標題列表 簡短摘要


可從此連結下載PowerShellIDE 1.03
http://www.scriptinternals.de/new/product/powershellideRC2.zip


ayowu 發表在 痞客邦 留言(0) 人氣()

可從以下連結下載Windows PowerShell 1.0

http://www.microsoft.com/technet/scriptcenter/topics/msh/download.mspx

[注意]電腦必須先安裝.NET Framework 2.0


安裝完成後可於   

ayowu 發表在 痞客邦 留言(0) 人氣()

若想要將PowerShell在此session中的所有執行過程以及執行結果(就是畫面上所有的東西)紀錄到某個檔案中,我們可以使用

PS C:\>Start-Transcript -path 檔案路徑

若欲結束紀錄則使用

ayowu 發表在 痞客邦 留言(0) 人氣()

http://blogs.iis.net/bills/archive/2006/11/14/powershell-rocks.aspx


ayowu 發表在 痞客邦 留言(1) 人氣()

http://channel9.msdn.com/Showpost.aspx?postid=256994


ayowu 發表在 痞客邦 留言(0) 人氣()

http://channel9.msdn.com/shows/The_DFO_Show


ayowu 發表在 痞客邦 留言(0) 人氣()

http://windowsvistablog.com/blogs/windowsvista/archive/2006/11/14/it-forum-day-one-windows-vista-and-windows-powershell.aspx

  • 12 Cool Features of Windows PowerShell
    1. Built-in Cmdlets (pronounced "commandlets") for Managing Windows
    2. The power of wildcards and working objects
    3. Whatif you could test your commands before committing to them
      • PS> stop-service w3* -whatif
    4. Take a transcript
      • PS> Start-Transcript -Path c:\demo\dfoshow.txt
        PS> Stop-Transcript
    5. Make Windows talk from the command line
      • PS> $spVoice = new-object -com "SAPI.spvoice"

ayowu 發表在 痞客邦 留言(0) 人氣()

http://www.iis.net/default.aspx?tabid=2&subtabid=25&i=1212

 

 

About Windows PowerShell

  • PS C:\> set-location Data
  • PS C:\Data> get-childitem Pow*
  • PS C:\Data> copy-item 'PowerShell' 'C:\Data\PSBackup' -recurse -force
    • 複製PowerShell資料夾及其底下所有的檔案與資料夾
  • PS C:\Data> remove-item PSBackup
    • 刪除PSBackup 資料夾及其底下所有的檔案與資料夾
  • PS C:\Data> get-content 'Hello.txt' | out-file '.\HelloCopy.txt'
  • PS C:\Data> get-content HelloCopy.txt
    • the get-content cmdlet is roughly equivalent to the type (Windows) or cat (Unix) commands
  • PS C:\Data> sl \
    • 使用set-location的alias sl 將目前路徑改為C:\
    • 查看sl為何者的alias
      • PS C:\> get-alias sl

             CommandType Name  Definition
              -----------           ----      ----------

ayowu 發表在 痞客邦 留言(0) 人氣()

http://channel9.msdn.com/ShowPost.aspx?PostID=256835


ayowu 發表在 痞客邦 留言(0) 人氣()

http://www.iis.net/1211/SinglePageArticle.ashx


ayowu 發表在 痞客邦 留言(0) 人氣()

一般情形下所設定的alias 其存續期間僅在此session內
因此關掉視窗之後alias則不存在
若想要保留此alias則需將其設定於Profile檔
<註>自行建立的function,variable也是如此

 

ayowu 發表在 痞客邦 留言(0) 人氣()

  • 用PowerShell寫Event Log
    • $a = new-object -type system.diagnostics.eventlog -argumentlist system   #寫到事件紀錄器的系統
    • $a.source = "Windows PowerShell Week"  #事件來源
    • $a.writeentry("This is just a test.","Information") #前者為事件內容 後者為事件的種類(包含 Error,FailureAudit,Information,SuccessAudit,Warning)
    • 一個source只能連結一種事件(應用程式,系統,安全性)
    • Remote Computer
      • $a = new-object -type system.diagnostics.eventlog -argumentlist system,ComputerName
  • PowerShell Formating Files
    • 一樣的get-process 得到不同的output
    • $PSHOME中的dotnettypes.format.ps1xml
    • <View>
          <Name>process</Name>
              <ViewSelectedBy>
                <TypeName>.NET Class Name</TypeName>
              </ViewSelectedBy>.....
      • System.Diagnostics.Process
    • <View>

ayowu 發表在 痞客邦 留言(0) 人氣()

 

  • 將1,2,3,4,5儲存於變數中,$a即為陣列
    PS C:\> $a =1,2,3,4,5
  • 顯示陣列元素個數
    PS C:\> $a.Length

ayowu 發表在 痞客邦 留言(0) 人氣()

所需執行的指令如果是會變動的(可能透過程式動態組合出的指令字串)如
"get-process " + "| sort-object  CPU -desc  " + " |select-object -first 3"
則我們可以透過Invoke-Expression指令執行之

上述三個字串分別代表

ayowu 發表在 痞客邦 留言(0) 人氣()

 

PS C:\>get-command

執行後畫面一直捲動 直到最後一筆
正常人應該無法一眼看完

ayowu 發表在 痞客邦 留言(0) 人氣()



  • 執行 PowerShell Script


ayowu 發表在 痞客邦 留言(0) 人氣()

  • 0.Object
    • object has..
      • Unique name
      • Properties
      • Methods
    • Like command tool
      • unique name
      • Let you do things
      • group together related functionality
      • Can be used from command prompt
    • Like output strings
      • Contain results
      • Can be parsed for particular bits of info
      • Can be used from command prompt
    • Type of object
      • COM obj
      • WMI obj
      • .NET framework obj
      • Windows powerShell obj
  • 1.Using Object
    • COM
      • $obj = new-object -comobject <PROGID>
      • $obj = new-object -com <PROGID>
        • PROGID look like "WScript.Network" and they stored in the registry HKEY_CLASSES_ROOT
      • Accessing Properties
        • $obj = new-object -com WScript.Network
        • $obj.Name
      • Setting Properties
        • $ExcelObj = new-object -com Excel.Application
        • $ExcelObj.Visible = $true
        • $WorkBookObj =  $ExcelObj.Workbooks.add()
        • $WorkSheetObj  = $WorkBookObj.Worksheets.Item(1)
        • $WorkSheetObj.Cells.Item(1.1) = "Feel the Power"
        • $ExcelObj.Quit
      • Calling Methods
        • $WorkBookObj =  $ExcelObj.Workbooks.add()
    • WMI
      • $obj = get-wmiobject -class <WMI Class>
      • $obj = get-wmiobject <WMI Class>
      • $obj = get-wmiobject -query <WQL>
      • Accessing Properties
        • $obj = get-wmiobject win32_process
        • $obj.WorkingSetSize
        • $obj | foreach-obkect {$_.ProcessName +":"+$_.WorkingSetSize}
      • Modifying Properties
        • $wmi_settings = get-wmiobject win32_wmisetting
        • $wmi_settings.ASPScriptDefaultNamespace = "root\default"
      • Calling methods
        • $obj = get-wmiobject win32_process -filter 'Name = "notepad.exe"'
        • $obj.GetOwner()
    • .NET framework
      • $obj = new-object -typeName <Fully-Qualified Name>
      • $obj = new-object <Fully-Qualified Name>
      • $obj = [ADSI]"LDAP://localhist:389/dc=NA,dc=fabrikam,dc=com"
        • $di = new-object System.IO.DiretoryInfo($PSHOME)
          • $PSHOME : home dir for PowerShell
      • Accessing Properties
        • $di = new-object System.IO.DiretoryInfo($PSHOME)
        • $di.CreationTime
      • Calling methods
      • UI
        • [System.Refleciotn.Assembly]::LoadWithPartialName(" System.windows.Forms")
        • $form = new-object System.Wondows.Forms.form
  • 2.Exploring Object
    • get-member
    • OLEView
    • Go to MSDN library
    • $objshell = get-object -com "Shell.Application" | get-member
    • $objFilder = $objshell.BrowseForFolder(0,"Pick Me!!",0)  //跳出瀏覽資料夾視窗
    • System.IO.DirectoryInfo  //namespace
    • $di = get-member -membertype Property
  • 3.Displaying Object
    • Many ways to "display" an object
    • Windows PowerShell provides a default way
    • XML config files let you change that default
    • 修改types.ps1xml檔以修改預設顯示欄位
      • $PSHOME\types.ps1xml
      • ... | format -list *
      • set-executionpolicy remotesigned
      • update-typedata
  • 4.Saving and Restoring Object
    • Export-Clixml saves a representation of the object to a file you can revive later
      • new-object -com "WScript.Network" | export-clixml "mothball.xml"
    • Import-Clixml restores the object from a file
      • $obj = import-clixml "mothball.xml"
  • 5.Copying and Modifying Object
    • Select-Object
      • Creates a new object by copying a portion of an exising one 
    • Add-Member
      • Augments an object by adding to an existing one
    • Add property using select-object
      • get-process | select-object ProcessName,@{Name="Start Day";Expression = {$_.startTime.DayofWeek}}
      • 上述物件型態:System.management.automation.PSCustomObject
    • Add property using add-mamber
      • $a = "thanks for watching windows powershell week"
      • $a = add-member -inputobject $a -membertype scriptmethod -name words -value {$this.splite()} -passthru
  • 6.Comparing Object
    • compare-object
      • $process = get-process
      • notepad
      • $processes_now = get-process
      • compare-object -ref $process -dif $process_now
      • $process_now | where-object {$_.Name -eq 'notepad'} | select-object Name,HasExited  //true

 

  • , $procs | get-member  //object[ ]

 

  • Reflection uses Get-Member
  • Simple,consistent,and use dot notation

ayowu 發表在 痞客邦 留言(0) 人氣()





ayowu 發表在 痞客邦 留言(0) 人氣()

第一天的webcast 重點如下




ayowu 發表在 痞客邦 留言(0) 人氣()

底下是一個有點簡單又不太簡單的powershell code


 

ayowu 發表在 痞客邦 留言(0) 人氣()