Adding custom types to PowerShell objects

Every PowerShell object is of some data type. For example, the process object is an instance of System.Diagnostics.Process type.

Get-Process | Get-Member
   TypeName: System.Diagnostics.Process

Objects that result from PowerShell commands execution belong to some data type, but this doesn’t prevent us from adding a custom type.

It becomes even more useful when we work with custom objects – System.Management.Automation.PSCustomObject.

    Name = 'Object'
    Description = 'Object Description'

Continue reading

Saving a PowerShell command for later use

Let’s suppose the following. You are working with PowerShell console and just finished typing a long and complex command. This second it occurs to you, that you forgot to define a variable, create a remote session or something else. You delete the command, execute some required actions, and type the command again.

Sounds familiar?

In this article we will talk about some techniques, that can help us out.

Continue reading