Leveraging .NET methods
With .NET, a method is some action that a .NET object occurrence, or the class, can perform. These methods form the basis for many PowerShell cmdlets. For example, you can stop a Windows process by using the Stop-Process
cmdlet. The cmdlet then uses the Kill()
method of the associated process object. As a general best practice, you should use cmdlets wherever possible. You should only use .NET classes and methods directly where there is no alternative.
.NET methods can be beneficial for performing operations which have no PowerShell cmdlets. And it can be useful too from the command line; for example, when you wish to kill a process. IT professionals are all too familiar with processes that are not responding and need to be killed, something you can do at the GUI using Task Manager. Or with PowerShell, you can use the Stop-Process
cmdlet, as discussed above. At the command line, where brevity is useful, you can use Get-Process
to find the process you want...