Skip to content

Commit c644c38

Browse files
matt9ucciSean Wheeler
authored and
Sean Wheeler
committed
Update Example 8 in Get-Process.md (find the owner of a process) (#1875)
* Update Example 8 in Get-Process.md (Find the owner of a process) * Update to attempt to avoid build errors It seems that the build system does not accept multiple script blocks per one Example header.
1 parent 496832f commit c644c38

File tree

5 files changed

+69
-96
lines changed

5 files changed

+69
-96
lines changed

reference/3.0/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ This command gets the modules for the processes that have names that begin with
114114

115115
To run this command on Windows Vista (and later versions of Windows) with processes that you do not own, you must start Windows PowerShell with the "Run as administrator" option.
116116
### Example 8
117-
```
118-
PS C:\> $p = get-wmiobject win32_process -filter "name='powershell.exe'"
119-
PS C:\> $p.getowner()
117+
```powershell
118+
PS C:\> $p = Get-WmiObject Win32_Process -Filter "name='powershell.exe'"
119+
PS C:\> $p.GetOwner()
120+
120121
121122
__GENUS : 2
122123
__CLASS : __PARAMETERS
@@ -134,15 +135,14 @@ User : user01
134135
```
135136

136137
This command shows how to find the owner of a process.
137-
Because the System.Diagnostics.Process object that Get-Process returns does not have a property or method that returns the process owner, the command uses
138+
Because the System.Diagnostics.Process object that `Get-Process` returns does not have a property or method that returns the process owner, the command uses the `Get-WmiObject` cmdlet to get a Win32_Process object that represents the same process.
138139

139-
the Get-WmiObject cmdlet to get a Win32_Process object that represents the same process.
140-
141-
The first command uses Get-WmiObject to get the PowerShell process.
140+
The first command uses `Get-WmiObject` to get the PowerShell process.
142141
It saves it in the $p variable.
143142

144143
The second command uses the GetOwner method to get the owner of the process in $p.
145-
The command reveals that the owner is Domain01\user01.
144+
The output reveals that the owner is Domain01\user01.
145+
146146
### Example 9
147147
```
148148
PS C:\> get-process powershell

reference/4.0/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,16 @@ This command gets the modules for the processes that have names that begin with
139139
To run this command on Windows Vista (and later versions of Windows) with processes that you do not own, you must start Windows PowerShell with the "Run as administrator" option.
140140

141141
### Example 8
142-
```
143-
PS C:\> $p = get-wmiobject win32_process -filter "name='powershell.exe'"
144-
PS C:\> $p.getowner()
142+
```powershell
143+
PS C:\> Get-Process powershell -IncludeUserName
144+
145+
Handles WS(K) CPU(s) Id UserName ProcessName
146+
------- ----- ------ -- -------- -----------
147+
782 132080 2.08 2188 DOMAIN01\user01 powershell
148+
149+
PS C:\> $p = Get-WmiObject Win32_Process -Filter "name='powershell.exe'"
150+
PS C:\> $p.GetOwner()
151+
145152
146153
__GENUS : 2
147154
__CLASS : __PARAMETERS
@@ -158,16 +165,17 @@ ReturnValue : 0
158165
User : user01
159166
```
160167

161-
This command shows how to find the owner of a process.
162-
Because the System.Diagnostics.Process object that Get-Process returns does not have a property or method that returns the process owner, the command uses
168+
The first command shows how to find the owner of a process.
169+
The **IncludeUserName** parameter requires elevated user rights (Run as Administrator).
170+
The output reveals that the owner is Domain01\user01.
163171

164-
the Get-WmiObject cmdlet to get a Win32_Process object that represents the same process.
172+
The second and third command are another way to find the owner of a process.
165173

166-
The first command uses Get-WmiObject to get the PowerShell process.
174+
The second command uses `Get-WmiObject` to get the PowerShell process.
167175
It saves it in the $p variable.
168176

169-
The second command uses the GetOwner method to get the owner of the process in $p.
170-
The command reveals that the owner is Domain01\user01.
177+
The third command uses the GetOwner method to get the owner of the process in $p.
178+
The output reveals that the owner is Domain01\user01.
171179

172180
### Example 9
173181
```

reference/5.0/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,46 +147,43 @@ This command gets the modules for the processes that have names that begin with
147147
To run this command on Windows Vista and later versions of Windows with processes that you do not own, you must start Windows PowerShell with the Run as administrator option.
148148

149149
### Example 8: Find the owner of a process
150-
```
151-
PS C:\> $P = Get-WmiObject win32_process -Filter "name='powershell.exe'"
152-
PS C:\> $P.getowner()
153-
154-
155-
156-
157-
158-
159-
160-
161-
162-
150+
```powershell
151+
PS C:\> Get-Process powershell -IncludeUserName
163152
153+
Handles WS(K) CPU(s) Id UserName ProcessName
154+
------- ----- ------ -- -------- -----------
155+
782 132080 2.08 2188 DOMAIN01\user01 powershell
164156
157+
PS C:\> $p = Get-WmiObject Win32_Process -Filter "name='powershell.exe'"
158+
PS C:\> $p.GetOwner()
165159
166160
167161
__GENUS : 2
168162
__CLASS : __PARAMETERS
169-
__SUPERCLASS :
163+
__SUPERCLASS :
170164
__DYNASTY : __PARAMETERS
171-
__RELPATH :
165+
__RELPATH :
172166
__PROPERTY_COUNT : 3
173167
__DERIVATION : {}
174-
__SERVER :
175-
__NAMESPACE :
176-
__PATH :
168+
__SERVER :
169+
__NAMESPACE :
170+
__PATH :
177171
Domain : DOMAIN01
178172
ReturnValue : 0
179173
User : user01
180174
```
181175

182-
This command shows how to find the owner of a process.
183-
Because the **System.Diagnostics.Process** object that **Get-Process** returns does not have a property or method that returns the process owner, the command uses the Get-WmiObject cmdlet to get a Win32_Process object that represents the same process.
176+
The first command shows how to find the owner of a process.
177+
The **IncludeUserName** parameter requires elevated user rights (Run as Administrator).
178+
The output reveals that the owner is Domain01\user01.
179+
180+
The second and third command are another way to find the owner of a process.
184181

185-
The first command uses **Get-WmiObject** to get the PowerShell process.
186-
It saves it in the $P variable.
182+
The second command uses `Get-WmiObject` to get the PowerShell process.
183+
It saves it in the $p variable.
187184

188-
The second command uses the **GetOwner** method to get the owner of the process in $P.
189-
The command reveals that the owner is Domain01\user01.
185+
The third command uses the GetOwner method to get the owner of the process in $p.
186+
The output reveals that the owner is Domain01\user01.
190187

191188
### Example 9: Use an automatic variable to identify the process hosting the current session
192189
```

reference/5.1/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,15 @@ This command gets the modules for the processes that have names that begin with
147147
To run this command on Windows Vista and later versions of Windows with processes that you do not own, you must start Windows PowerShell with the Run as administrator option.
148148

149149
### Example 8: Find the owner of a process
150-
```
151-
PS C:\> $P = Get-WmiObject win32_process -Filter "name='powershell.exe'"
152-
PS C:\> $P.getowner()
153-
154-
155-
156-
157-
158-
159-
160-
161-
162-
150+
```powershell
151+
PS C:\> Get-Process powershell -IncludeUserName
163152
153+
Handles WS(K) CPU(s) Id UserName ProcessName
154+
------- ----- ------ -- -------- -----------
155+
782 132080 2.08 2188 DOMAIN01\user01 powershell
164156
157+
PS C:\> $p = Get-WmiObject Win32_Process -Filter "name='powershell.exe'"
158+
PS C:\> $p.GetOwner()
165159
166160
167161
__GENUS : 2
@@ -179,14 +173,17 @@ ReturnValue : 0
179173
User : user01
180174
```
181175

182-
This command shows how to find the owner of a process.
183-
Because the **System.Diagnostics.Process** object that **Get-Process** returns does not have a property or method that returns the process owner, the command uses the Get-WmiObject cmdlet to get a Win32_Process object that represents the same process.
176+
The first command shows how to find the owner of a process.
177+
The **IncludeUserName** parameter requires elevated user rights (Run as Administrator).
178+
The output reveals that the owner is Domain01\user01.
179+
180+
The second and third command are another way to find the owner of a process.
184181

185-
The first command uses **Get-WmiObject** to get the PowerShell process.
186-
It saves it in the $P variable.
182+
The second command uses `Get-WmiObject` to get the PowerShell process.
183+
It saves it in the $p variable.
187184

188-
The second command uses the **GetOwner** method to get the owner of the process in $P.
189-
The command reveals that the owner is Domain01\user01.
185+
The third command uses the GetOwner method to get the owner of the process in $p.
186+
The output reveals that the owner is Domain01\user01.
190187

191188
### Example 9: Use an automatic variable to identify the process hosting the current session
192189
```

reference/6/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -152,46 +152,17 @@ This command gets the modules for the processes that have names that begin with
152152
To run this command on Windows Vista and later versions of Windows with processes that you do not own, you must start Windows PowerShell with the Run as administrator option.
153153

154154
### Example 8: Find the owner of a process
155-
```
156-
PS C:\> $P = Get-WmiObject win32_process -Filter "name='powershell.exe'"
157-
PS C:\> $P.getowner()
158-
159-
160-
161-
162-
163-
164-
155+
```powershell
156+
PS C:\> Get-Process pwsh -IncludeUserName
165157
166-
167-
168-
169-
170-
171-
172-
__GENUS : 2
173-
__CLASS : __PARAMETERS
174-
__SUPERCLASS :
175-
__DYNASTY : __PARAMETERS
176-
__RELPATH :
177-
__PROPERTY_COUNT : 3
178-
__DERIVATION : {}
179-
__SERVER :
180-
__NAMESPACE :
181-
__PATH :
182-
Domain : DOMAIN01
183-
ReturnValue : 0
184-
User : user01
158+
Handles WS(K) CPU(s) Id UserName ProcessName
159+
------- ----- ------ -- -------- -----------
160+
782 132080 2.08 2188 DOMAIN01\user01 pwsh
185161
```
186162

187163
This command shows how to find the owner of a process.
188-
Because the **System.Diagnostics.Process** object that **Get-Process** returns does not have a property or method that returns the process owner, the command uses the Get-WmiObject cmdlet to get a Win32_Process object that represents the same process.
189-
190-
The first command uses **Get-WmiObject** to get the PowerShell process.
191-
It saves it in the $P variable.
192-
193-
The second command uses the **GetOwner** method to get the owner of the process in $P.
194-
The command reveals that the owner is Domain01\user01.
164+
On Windows, the **IncludeUserName** parameter requires elevated user rights (Run as Administrator).
165+
The output reveals that the owner is Domain01\user01.
195166

196167
### Example 9: Use an automatic variable to identify the process hosting the current session
197168
```

0 commit comments

Comments
 (0)