power shell

Post on 15-May-2015

193 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Powershell JASON

Powershell

Function

ScriptBlock

New-Object

Format-Table

Convert-Html

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

Function ?

ScriptBlock ?

ScriptBlock

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

Execute &$block

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

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

利用 filter function

Filter Functionfunction Get-FileSize{ begin {

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

dir *.txt | Get-FileSize

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

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

Example3

$process = Get-Process | select -First 10

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

$list

Format-Table (ft)

$list | Format-Table -AutoSize

Format-List (fl)

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

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

top related