SlideShare a Scribd company logo
1 of 22
PowerShell – Object 篇
2013/11/18 Howard
GetType
•

可使用 GetType() 方法取得物件類型
Array

• Element 用「,」分隔,建立 object array
如何建立 empty array
•

@()

•

建立 array 的方式,也可以用 @(………)

•

•

Element 用「,」分隔

利用數值區間來建立陣列

•

(startIndex..endIndex)
取得 array 資料

• 可以用 [index], [StartIndex..EndIndex] 取得資料

• 以上例,$array[3] 的輸出是什麼
• 以上例,$array[0,-1] 的輸出是什麼
Array method
• -contains
• -notcontains
• 不區分大小寫
Array method
• 字串查詢時,注意型態轉換

• 使用迴圈或 Where-Object 避免型別問題
Dictionary

• System.Collections.Hashtable

• 存取字典方式:
Dictionary method
• 移除元素 Remove()
• Contains(), ContainsKey() 查找是否有存在給定的 Key
• ContainsValue 查找是否有存在的 Value

• Keys, Values 列舉資料
值比較
•
•
•
•
•
•

-eq

•

equal

-ne

•

Not-equal

-lt

•

Less-than

-gt

•

Greater-than

-le

•

Less-than-or-equal

-ge

•

Greater-than-or-equal
值比較
•

字串比較區分大小寫

• -ceq, -cne, -clt, -cle, -cgt, -cge
Foreach-Object
• 與 foreach 同名
$_
• 指的是當前物件的索引
• 如同 JavaScript 中的 this
Where-Object
• 與 where, ? 同名
• 過濾並反回符合條件的項目
• 同 SQL 的 where
Select-Object

• 簡寫為 select
• 用來新建包含原始物件屬性子集的物件集合
• 同 SQL 的 select
Sort-Object
• 簡寫為 sort
• 可按照一個或多個屬性排序集合
Tee-Object
• 簡稱 tee
• 把集合傳遞給下一個命令前,保存當前管道到檔案或變數
• 可在執行特定階段保存集合,並在後面的命令中使用這個集合
Group-Object
• 簡稱 group
• 將物件集合按照屬性值分為多個 Group
Measure-Object
• 計集集合的統計值
• 取得最小值、最大值、平均值等資訊
Compare-Object
• 簡稱 diff
• 比較兩個物件或集合並回傳不同的資訊
Q1
• 列出你 pc 中的 service 列表
•
•

get-service
其中狀態是「執行中」且 名稱是「Win 開頭」,再按照「名稱」降幂排序。
Reference

More Related Content

What's hot

Java SE 8 技術手冊第 9 章 - Collection與Map
Java SE 8 技術手冊第 9 章 - Collection與MapJava SE 8 技術手冊第 9 章 - Collection與Map
Java SE 8 技術手冊第 9 章 - Collection與MapJustin Lin
 
浅尝jQuery
浅尝jQuery浅尝jQuery
浅尝jQueryfangdeng
 
8. 常用標準API
8. 常用標準API8. 常用標準API
8. 常用標準APIJustin Lin
 
9. 資料結構
9. 資料結構9. 資料結構
9. 資料結構Justin Lin
 
型態與運算子
型態與運算子型態與運算子
型態與運算子Justin Lin
 

What's hot (6)

資料結構
資料結構資料結構
資料結構
 
Java SE 8 技術手冊第 9 章 - Collection與Map
Java SE 8 技術手冊第 9 章 - Collection與MapJava SE 8 技術手冊第 9 章 - Collection與Map
Java SE 8 技術手冊第 9 章 - Collection與Map
 
浅尝jQuery
浅尝jQuery浅尝jQuery
浅尝jQuery
 
8. 常用標準API
8. 常用標準API8. 常用標準API
8. 常用標準API
 
9. 資料結構
9. 資料結構9. 資料結構
9. 資料結構
 
型態與運算子
型態與運算子型態與運算子
型態與運算子
 

Viewers also liked

Bootstrap - component
Bootstrap - componentBootstrap - component
Bootstrap - componentLearningTech
 
Asp.net controller
Asp.net controllerAsp.net controller
Asp.net controllerLearningTech
 
Vs 2012 publishing profiles and copy files using ms builld commands
Vs 2012 publishing profiles and copy files using ms builld commandsVs 2012 publishing profiles and copy files using ms builld commands
Vs 2012 publishing profiles and copy files using ms builld commandsLearningTech
 
Self-Hosta Web API
Self-Hosta Web APISelf-Hosta Web API
Self-Hosta Web APILearningTech
 
Css 選擇器規劃
Css 選擇器規劃Css 選擇器規劃
Css 選擇器規劃LearningTech
 

Viewers also liked (8)

Bootstrap - component
Bootstrap - componentBootstrap - component
Bootstrap - component
 
Tuple
TupleTuple
Tuple
 
Asp.net controller
Asp.net controllerAsp.net controller
Asp.net controller
 
Vs 2012 publishing profiles and copy files using ms builld commands
Vs 2012 publishing profiles and copy files using ms builld commandsVs 2012 publishing profiles and copy files using ms builld commands
Vs 2012 publishing profiles and copy files using ms builld commands
 
Self-Hosta Web API
Self-Hosta Web APISelf-Hosta Web API
Self-Hosta Web API
 
Knockout extender
Knockout extenderKnockout extender
Knockout extender
 
Sse
SseSse
Sse
 
Css 選擇器規劃
Css 選擇器規劃Css 選擇器規劃
Css 選擇器規劃
 

Similar to Power shell – object 篇

使用 Eloquent ORM
使用 Eloquent ORM使用 Eloquent ORM
使用 Eloquent ORMShengyou Fan
 
02 Objective-C
02 Objective-C02 Objective-C
02 Objective-CTom Fan
 
Java SE 7 技術手冊投影片第 04 章 - 認識物件
Java SE 7 技術手冊投影片第 04 章 - 認識物件Java SE 7 技術手冊投影片第 04 章 - 認識物件
Java SE 7 技術手冊投影片第 04 章 - 認識物件Justin Lin
 
型態與運算子
型態與運算子型態與運算子
型態與運算子Justin Lin
 
Java SE 8 技術手冊第 4 章 - 認識物件
Java SE 8 技術手冊第 4 章 - 認識物件Java SE 8 技術手冊第 4 章 - 認識物件
Java SE 8 技術手冊第 4 章 - 認識物件Justin Lin
 
Java SE 7 技術手冊投影片第 09 章 - Collection與Map
Java SE 7 技術手冊投影片第 09 章 - Collection與MapJava SE 7 技術手冊投影片第 09 章 - Collection與Map
Java SE 7 技術手冊投影片第 09 章 - Collection與MapJustin Lin
 
5, initialization & cleanup
5, initialization & cleanup5, initialization & cleanup
5, initialization & cleanupted-xu
 

Similar to Power shell – object 篇 (7)

使用 Eloquent ORM
使用 Eloquent ORM使用 Eloquent ORM
使用 Eloquent ORM
 
02 Objective-C
02 Objective-C02 Objective-C
02 Objective-C
 
Java SE 7 技術手冊投影片第 04 章 - 認識物件
Java SE 7 技術手冊投影片第 04 章 - 認識物件Java SE 7 技術手冊投影片第 04 章 - 認識物件
Java SE 7 技術手冊投影片第 04 章 - 認識物件
 
型態與運算子
型態與運算子型態與運算子
型態與運算子
 
Java SE 8 技術手冊第 4 章 - 認識物件
Java SE 8 技術手冊第 4 章 - 認識物件Java SE 8 技術手冊第 4 章 - 認識物件
Java SE 8 技術手冊第 4 章 - 認識物件
 
Java SE 7 技術手冊投影片第 09 章 - Collection與Map
Java SE 7 技術手冊投影片第 09 章 - Collection與MapJava SE 7 技術手冊投影片第 09 章 - Collection與Map
Java SE 7 技術手冊投影片第 09 章 - Collection與Map
 
5, initialization & cleanup
5, initialization & cleanup5, initialization & cleanup
5, initialization & cleanup
 

More from LearningTech

More from LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection & activator
Reflection & activatorReflection & activator
Reflection & activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Power shell – object 篇

Editor's Notes

  1. Key 值,不限定一定要字串