Jason
Array   > $a = 1, 2, 3, 4, 5   String.Object[]   > $b = 1, “C”, 2.99, (Get-Process)   可用 @() ,表示新增 Array
Array   > $a = 2, 3, 4   > $a[0, 2]   > $a[0, -1]   > $a[1] = 10, 20, 30   > $a = $a + 1
Array   > 1, 2, 3, 4 –contains 4   > 1, 2, 3,4 –notcontains 3   > 1, 2, 3 –contains “3”   > 1, 2, “03” –contains 3
ForEach-Object簡寫為 foreach> 1,2,3 | ForEach-Object { $_ * 2 }或> 1,2,3 | foreach { $_ * 2 }
Select-Object簡寫為 select> Get-Process chrome | Select-Object ProcessName,Id
Sort-Object簡寫為 sortGet-Process chrome | Sort-Object IdGet-Process chrome | Sort-Object Id -Descending
Tee-Object簡寫為 tee>3,2,1 | Tee-Object -Variable unsorted | Sort-Object123>$unsorted321
Group-Object簡寫為 group> dir | Group-Object -Property ExtensionCount Name                 Group----- ----                ---...
Measure-Object>1,2,3,4 | Measure-Object -Sum -Max -Min -AverageCount : 4Average : 2.5Sum    : 10Maximum : 4Minimum : 1
Compare-Object簡寫為 diff>$a = @(1,2,4)>$b = @(1,3,4)>Compare-Object -ReferenceObject $a -DifferenceObject $b>Compare-Object ...
Read Word FileProgID : Word.Application$wordApp = New-Object -COM Word.Application$file = (dir Test.docx).FullName$doc = $...
Create Word File$path = Join-Path (Get-Location) create.doc$wordApp = New-Object -COM Word.Application#$wordApp.Visible = ...
Edit Word File$wordApp = New-Object -COM Word.Application$file = (dir Test.docx).FullName$doc = $wordApp.Documents.Open($f...
Referencehttp://technet.microsoft.com/zh-TW/library/dd315334.aspxhttp://www.books.com.tw/exep/prod/booksfile.php?item=0010...
Upcoming SlideShare
Loading in...5
×

Power shell object

248

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
248
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Power shell object

  1. 1. Jason
  2. 2. Array > $a = 1, 2, 3, 4, 5 String.Object[] > $b = 1, “C”, 2.99, (Get-Process) 可用 @() ,表示新增 Array
  3. 3. Array > $a = 2, 3, 4 > $a[0, 2] > $a[0, -1] > $a[1] = 10, 20, 30 > $a = $a + 1
  4. 4. Array > 1, 2, 3, 4 –contains 4 > 1, 2, 3,4 –notcontains 3 > 1, 2, 3 –contains “3” > 1, 2, “03” –contains 3
  5. 5. ForEach-Object簡寫為 foreach> 1,2,3 | ForEach-Object { $_ * 2 }或> 1,2,3 | foreach { $_ * 2 }
  6. 6. Select-Object簡寫為 select> Get-Process chrome | Select-Object ProcessName,Id
  7. 7. Sort-Object簡寫為 sortGet-Process chrome | Sort-Object IdGet-Process chrome | Sort-Object Id -Descending
  8. 8. Tee-Object簡寫為 tee>3,2,1 | Tee-Object -Variable unsorted | Sort-Object123>$unsorted321
  9. 9. Group-Object簡寫為 group> dir | Group-Object -Property ExtensionCount Name Group----- ---- ----- 1 .android {.android} 1 .10 {.gstreamer-0.10} 16 {Contacts, Desktop, Documents, Downloads...} 1 .kdiff3rc {.kdiff3rc} 1 .userId {.org.eclipse.epp.usagedata.recording.userId} 1 .txt {a.txt} 1 .ini {mercurial.ini}
  10. 10. Measure-Object>1,2,3,4 | Measure-Object -Sum -Max -Min -AverageCount : 4Average : 2.5Sum : 10Maximum : 4Minimum : 1
  11. 11. Compare-Object簡寫為 diff>$a = @(1,2,4)>$b = @(1,3,4)>Compare-Object -ReferenceObject $a -DifferenceObject $b>Compare-Object $a $bInputObject SideIndicator ----------- ------------- 3 => 2 <=
  12. 12. Read Word FileProgID : Word.Application$wordApp = New-Object -COM Word.Application$file = (dir Test.docx).FullName$doc = $wordApp.Documents.Open($file)$text = $doc.Content.Text$text$wordApp.Exit
  13. 13. Create Word File$path = Join-Path (Get-Location) create.doc$wordApp = New-Object -COM Word.Application#$wordApp.Visible = $trueif (Test-Path $path){ del $path}$doc = $wordApp.Documents.Add()$doc.Content.Text = "This is a book!!"$doc.SaveAs($path)$wordApp.Quit()
  14. 14. Edit Word File$wordApp = New-Object -COM Word.Application$file = (dir Test.docx).FullName$doc = $wordApp.Documents.Open($file)$documentFront = $doc.Content$documentFront.End = $start.Start$documentFront.Text ="Sorry"$documentFront.Font.Name="Times new roman"$documentFront.Font.ColorIndex = 6$doc.save()$wordApp.Quit()
  15. 15. Referencehttp://technet.microsoft.com/zh-TW/library/dd315334.aspxhttp://www.books.com.tw/exep/prod/booksfile.php?item=00104 http://powershell.com/cs/blogs/ebook/default.aspx
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×