Working with the .NET Framework

One feature that gives PowerShell its incredible reach into both system administration and application development is its ability to leverage Microsoft’s enormous and broad .NET Framework.

The .NET Framework is a large collection of classes. Each class embodies a specific concept, and groups closely related functionality and information.

An example of such a class is System.Diagnostics.Process—the grouping of functionality that “provides access to local and remote processes, and enables you to start and stop local system processes.”

Classes contain methods (which allow you to perform operations) and properties (which allow you to access information.)

The terms type and class can be used interchangeably.

Static Methods

[ClassName]::MethodName(parameter list)

Some methods relate only to the concept the class represents. For example, retrieving all running processes on a system relates to the general concept of processes. Methods that apply to the class/type as a whole are called static methods.

For example:

PS >[System.Diagnostics.Process]::GetProcessById(0)

gets the process with the ID of 0 and displays the following output:

Handles  NPM(K)    PM(K)      WS(K)  VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      -----  -----   ------     -- -----------
    0     0      0     16               0 0 Idle

Instance Methods

$objectReference.MethodName(parameter list)

Some methods relate only to specific, tangible realizations (called instances) of a class. An example of this would be a process actually running on the system, ...

Get Windows PowerShell Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.