Uploaded on

 

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
129
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • http://technet.microsoft.com/en-us/library/hh849944.aspx

Transcript

  • 1. Powershell JASON
  • 2. Powershell  Function  ScriptBlock  New-Object  Format-Table  Convert-Html
  • 3. 輸入某數,算出該數階乘(Factorial)  Function ?  ScriptBlock ?
  • 4. ScriptBlock  $block = { Write-Host “Hello ScriptBlock” }  Execute  &$block
  • 5. 取得目前近 5 分鐘內的 Process info  Get-Process | Get-RecentlyStarted  利用 begin、process、end  利用 filter function
  • 6. Filter Function function Get-FileSize { begin { …… } process { ….. } end { …. } } dir *.txt | Get-FileSize
  • 7. Example1 $process = Get-Process | select -First 10 $list = @() foreach($p in $process) { $info = New-Object PSObject $info | Add-Member -type NoteProperty -name Name -Value $p.ProcessName $info | Add-Member -type NoteProperty -name Pid -Value $p.Id } $list += $info $list
  • 8. Example2 $process = Get-Process | select -First 10 $list = @() foreach($p in $process) { $info = New-Object PSObject -Property @{ Name = $p.ProcessName; Pid = $p.Id } $list += $info } $list
  • 9. Example3 $process = Get-Process | select -First 10 $list = $process | select @{Name=“Name”;Expression= { $_.ProcessName} }, @{Name=“Pid”; Expression= { $_.Id } } $list
  • 10. Format-Table (ft) $list | Format-Table -AutoSize
  • 11. Format-List (fl) $list | Format-List $list | Format-List -GroupBy Name
  • 12. ConvertTo-Html (cth) $list | ConvertTo-HTML -cssuri "Layout.css" -title "Process" -body "<H2>Process Info</H2>" -pre (get-date) -post (get-date)