-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3-CommonCommands.dib
More file actions
185 lines (95 loc) · 2.92 KB
/
3-CommonCommands.dib
File metadata and controls
185 lines (95 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!markdown
# Common Commands
<hr />
#!markdown
### Get-Help
**Alias:** help
*note: using the `help` alias will paginate the help page*
**Description:** Displays information about PowerShell commands and concepts.
#!pwsh
Get-Help Get-Command
#!markdown
### Get-Command
**Alias:** gcm
**Description:** Used to get information on commands. Can be used on its own or by limiting search to Noun and/or Verb `Get-Command -Noun *file*`, `Get-Command -Verb *delete*`
#!pwsh
Get-Command -Name Start-Process
#!pwsh
Get-Command -Noun Process
#!pwsh
Get-Command -Verb ConvertTo
#!pwsh
Get-Command -Verb Convert* -TotalCount 5
#!markdown
### Get-Member
**Alias:** gm
**Description:** Gets the properties and methods of objects.
#!pwsh
$notepadProcess = Start-Process notepad -PassThru
Get-Member -InputObject $notepadProcess
#!markdown
### Measure-Object
**Alias:** measure
**Description:** Calculates the numeric properties of objects, and the characters, words, and lines in string objects, such as files of text.
#!pwsh
Get-Command | Measure-Object
#!pwsh
1..10 | Measure-Object -AllStats
#!markdown
### Foreach-Object
**Alias:** % or foreach
**Description:** Performs an operation against each item in a collection of input objects.
#!pwsh
1..5 | ForEach-Object { $_ }
#!markdown
### Where-Object
**Alias:** ? or where
**Description:** Selects objects from a collection based on their property values.
#!pwsh
1..5 | Where-Object { $_ -gt 3 }
#!markdown
### Select-Object
**Alias:** select
**Description:** Selects objects or object properties.
#!pwsh
1..5 | Select-Object -First 3
#!pwsh
1..5 | Select-Object -Skip 2 -First 2
#!pwsh
Get-Process | Select-Object -ExpandProperty Name -First 3
#!markdown
### Invoke-RestMethod
**Alias:** irm
**Description:** Sends an HTTP or HTTPS request to a RESTful web service.
#!pwsh
Invoke-RestMethod -Method 'Get' -Uri "https://jsonplaceholder.typicode.com/todos/1"
#!pwsh
$todos = Invoke-RestMethod -Method 'Get' -Uri "https://jsonplaceholder.typicode.com/todos"
$todos | Measure-Object
#!markdown
### Get-History
**Alias:** history or h or ghy
**Description:** Gets a list of the commands entered during the current session.
#!pwsh
Get-History
#!pwsh
Get-History -Count 5
#!pwsh
Get-History -Count 5 | Select-Object -ExpandProperty CommandLine
#!pwsh
Get-History -Count 5 | Select-Object -ExpandProperty CommandLine > commands.ps1
#!markdown
### ConvertTo-Json
**Alias:** n/a
**Description:** Converts an object to a JSON-formatted string.
#!pwsh
Get-History | Select-Object -First 2 | ForEach-Object { [pscustomobject]@{ id = $_.Id; commandLine = $_.CommandLine } } | ConvertTo-Json
#!markdown
### Format-List
**Alias:** fl
**Description:** Formats the output as a list of properties in which each property appears on a new line.
#!pwsh
# default is to output to a table
Get-History | Select-Object -First 2
#!pwsh
Get-History | Select-Object -First 2 | Format-List