Skip to content

Latest commit

 

History

History
70 lines (62 loc) · 1.11 KB

File metadata and controls

70 lines (62 loc) · 1.11 KB

Working with many objects, one at a time

Get-Service | gm -Name pause

output:

TypeName: System.ServiceProcess.ServiceController

Name  MemberType Definition  
----  ---------- ----------  
Pause Method     void Pause()

Get-Process | gm -Name kill

output:

TypeName: System.Diagnostics.Process

Name MemberType Definition 
---- ---------- ---------- 
Kill Method     void Kill()

Get-CimClass -ClassName Win32_Process | Select-Object -ExpandProperty CimClassMethods

Look for Terminate:


1.

Get-Process -Name Notepad | Stop-Process

2.

Get-Process -Name Notepad | ForEach-Object {$_.kill()}

3.

Get-CimInstance -ClassName Win32_Process -filter "name = 'notepad.exe'" | Invoke-CimMethod -MethodName Terminate

4. (It's an answer but not really practical for working with objects)

Stop-Process -Name Notepad

Get-Content C:\dev\servers.txt | ForEach-Object {$_.toUpper()}

output:

SERVER1
SERVERB
SERVER#
REVRES3
REVRESB
REVRES!