File tree Expand file tree Collapse file tree 4 files changed +76
-49
lines changed
5.1/Microsoft.PowerShell.Management
7.4/Microsoft.PowerShell.Management
7.5/Microsoft.PowerShell.Management
7.6/Microsoft.PowerShell.Management Expand file tree Collapse file tree 4 files changed +76
-49
lines changed Original file line number Diff line number Diff line change @@ -198,37 +198,24 @@ Handles WS(K) CPU(s) Id UserName ProcessName
198198```
199199
200200``` powershell
201- $p = Get-WmiObject Win32_Process -Filter "name='powershell.exe'"
202- $p. GetOwner()
201+ Get-CimInstance -ClassName Win32_Process -Filter "name='powershell.exe'" |
202+ Invoke-CimMethod -MethodName GetOwner
203203```
204204
205205``` Output
206- __GENUS : 2
207- __CLASS : __PARAMETERS
208- __SUPERCLASS :
209- __DYNASTY : __PARAMETERS
210- __RELPATH :
211- __PROPERTY_COUNT : 3
212- __DERIVATION : {}
213- __SERVER :
214- __NAMESPACE :
215- __PATH :
216- Domain : DOMAIN01
217- ReturnValue : 0
218- User : user01
219- ```
220-
221- The first command shows how to find the owner of a process. The ** IncludeUserName** parameter
222- requires elevated user rights (** Run as Administrator** ). The output reveals that the owner is
223- ` Domain01\user01 ` .
224-
225- The second and third command are another way to find the owner of a process.
206+ Domain ReturnValue User PSComputerName
207+ ------ ----------- ---- --------------
208+ DOMAIN01 0 user01
209+ ```
226210
227- The second command uses ` Get-WmiObject ` to get the PowerShell process.
228- It saves it in the ` $p ` variable.
211+ The first command shows how to get the owner of a process. The ** IncludeUserName** parameter
212+ requires elevated user rights (** Run as Administrator** ). The output reveals that the owner is
213+ ` DOMAIN01\user01 ` .
229214
230- The third command uses the ** GetOwner** method to get the owner of the process in ` $p ` . The output
231- reveals that the owner is ` Domain01\user01 ` .
215+ The second pipeline shows a different way to get the owner of a process using ` Get-CimInstance ` and
216+ ` Invoke-CimMethod ` . The ** Win32_Process** class with a filter retrieves ` powershell ` processes and
217+ the invoked ` GetOwner() ` method returns information on the process's ** Domain** and ** User** . This
218+ method doesn't require elevated user rights.
232219
233220### Example 9: Use an automatic variable to identify the process hosting the current session
234221
Original file line number Diff line number Diff line change @@ -189,15 +189,29 @@ Get-Process pwsh -IncludeUserName
189189```
190190
191191``` Output
192- Handles WS(K ) CPU(s) Id UserName ProcessName
193- ------- ----- ------ -- -------- -----------
194- 782 132080 2.08 2188 DOMAIN01\user01 pwsh
192+ WS(M ) CPU(s) Id UserName ProcessName
193+ ----- ------ -- -------- -----------
194+ 46.53 21.70 3188 DOMAIN01\user01 pwsh
195195```
196196
197- This command shows how to find the owner of a process.
198- On Windows, the ** IncludeUserName** parameter requires elevated user rights
199- (** Run as Administrator** ).
200- The output reveals that the owner is ` Domain01\user01 ` .
197+ ``` powershell
198+ Get-CimInstance -ClassName Win32_Process -Filter "name='pwsh.exe'" |
199+ Invoke-CimMethod -MethodName GetOwner
200+ ```
201+
202+ ``` Output
203+ Domain ReturnValue User PSComputerName
204+ ------ ----------- ---- --------------
205+ DOMAIN01 0 user01
206+ ```
207+
208+ The first command shows how to get the owner of a process. The output reveals that the owner is
209+ ` DOMAIN01\user01 ` .
210+
211+ The second pipeline shows a different way to get the owner of a process using ` Get-CimInstance ` and
212+ ` Invoke-CimMethod ` . The ** Win32_Process** class with a filter retrieves ` pwsh ` processes and the
213+ invoked ` GetOwner() ` method returns information on the process's ** Domain** and ** User** . This
214+ method is only available on Windows and doesn't require elevated user rights.
201215
202216### Example 9: Use an automatic variable to identify the process hosting the current session
203217
Original file line number Diff line number Diff line change @@ -189,16 +189,29 @@ Get-Process pwsh -IncludeUserName
189189```
190190
191191``` Output
192- Handles WS(K ) CPU(s) Id UserName ProcessName
193- ------- ----- ------ -- -------- -----------
194- 782 132080 2.08 2188 DOMAIN01\user01 pwsh
192+ WS(M ) CPU(s) Id UserName ProcessName
193+ ----- ------ -- -------- -----------
194+ 46.53 21.70 3188 DOMAIN01\user01 pwsh
195195```
196196
197- This command shows how to find the owner of a process.
198- On Windows, the ** IncludeUserName** parameter requires elevated user rights
199- (** Run as Administrator** ) to view the users of processes that aren't running
200- as the current user.
201- The output reveals that the owner is ` Domain01\user01 ` .
197+ ``` powershell
198+ Get-CimInstance -ClassName Win32_Process -Filter "name='pwsh.exe'" |
199+ Invoke-CimMethod -MethodName GetOwner
200+ ```
201+
202+ ``` Output
203+ Domain ReturnValue User PSComputerName
204+ ------ ----------- ---- --------------
205+ DOMAIN01 0 user01
206+ ```
207+
208+ The first command shows how to get the owner of a process. The output reveals that the owner is
209+ ` DOMAIN01\user01 ` .
210+
211+ The second pipeline shows a different way to get the owner of a process using ` Get-CimInstance ` and
212+ ` Invoke-CimMethod ` . The ** Win32_Process** class with a filter retrieves ` pwsh ` processes and the
213+ invoked ` GetOwner() ` method returns information on the process's ** Domain** and ** User** . This
214+ method is only available on Windows and doesn't require elevated user rights.
202215
203216### Example 9: Use an automatic variable to identify the process hosting the current session
204217
Original file line number Diff line number Diff line change @@ -189,16 +189,29 @@ Get-Process pwsh -IncludeUserName
189189```
190190
191191``` Output
192- Handles WS(K ) CPU(s) Id UserName ProcessName
193- ------- ----- ------ -- -------- -----------
194- 782 132080 2.08 2188 DOMAIN01\user01 pwsh
192+ WS(M ) CPU(s) Id UserName ProcessName
193+ ----- ------ -- -------- -----------
194+ 46.53 21.70 3188 DOMAIN01\user01 pwsh
195195```
196196
197- This command shows how to find the owner of a process.
198- On Windows, the ** IncludeUserName** parameter requires elevated user rights
199- (** Run as Administrator** ) to view the users of processes that aren't running
200- as the current user.
201- The output reveals that the owner is ` Domain01\user01 ` .
197+ ``` powershell
198+ Get-CimInstance -ClassName Win32_Process -Filter "name='pwsh.exe'" |
199+ Invoke-CimMethod -MethodName GetOwner
200+ ```
201+
202+ ``` Output
203+ Domain ReturnValue User PSComputerName
204+ ------ ----------- ---- --------------
205+ DOMAIN01 0 user01
206+ ```
207+
208+ The first command shows how to get the owner of a process. The output reveals that the owner is
209+ ` DOMAIN01\user01 ` .
210+
211+ The second pipeline shows a different way to get the owner of a process using ` Get-CimInstance ` and
212+ ` Invoke-CimMethod ` . The ** Win32_Process** class with a filter retrieves ` pwsh ` processes and the
213+ invoked ` GetOwner() ` method returns information on the process's ** Domain** and ** User** . This
214+ method is only available on Windows and doesn't require elevated user rights.
202215
203216### Example 9: Use an automatic variable to identify the process hosting the current session
204217
You can’t perform that action at this time.
0 commit comments