13
Powershell JASON

Power shell

Embed Size (px)

Citation preview

Page 1: Power shell

Powershell JASON

Page 2: Power shell

Powershell

Function

ScriptBlock

New-Object

Format-Table

Convert-Html

Page 3: Power shell

輸入某數,算出該數階乘 (Factorial)

Function ?

ScriptBlock ?

Page 4: Power shell

ScriptBlock

$block = { Write-Host “Hello ScriptBlock” }

Execute &$block

Page 5: Power shell

取得目前近 5 分鐘內的 Process info

Get-Process | Get-RecentlyStarted 利用 begin 、 process 、 end

利用 filter function

Page 6: Power shell

Filter Functionfunction Get-FileSize{ begin {

…… } process { ….. } end { …. }}

dir *.txt | Get-FileSize

Page 7: Power shell
Page 8: Power shell

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

Page 9: Power shell

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

Page 10: Power shell

Example3

$process = Get-Process | select -First 10

$list = $process | select @{Name=“Name”;Expression= { $_.ProcessName} }, @{Name=“Pid”; Expression= { $_.Id } }

$list

Page 11: Power shell

Format-Table (ft)

$list | Format-Table -AutoSize

Page 12: Power shell

Format-List (fl)

$list | Format-List $list | Format-List -GroupBy Name

Page 13: Power shell

ConvertTo-Html (cth) $list | ConvertTo-HTML -cssuri "Layout.css" -title "Process" -body "<H2>Process Info</H2>" -pre (get-date) -post (get-date)