Creating PowerShell Custom Objects

Whilst rarely needed when running PowerShell commands in the console, creating custom objects can be a useful technique when writing scripts or functions.  The typical use of custom objects is where you want to retrieve information from multiple sources and combine it for manipulation or display purposes.

There are several different ways that we can go about creating custom objects.  These include:

  • Abusing an existing object
  • Creating a PSCustom object
  • Creating a PSCustom object from a hash table
  • Build your own .NET class (PowerShell 5.0)

Abusing an Existing Object

The –Property parameter of Select-Object will allow you select the properties of an object to be used subsequently in the pipeline.  One use of this is to return fewer properties than were previously used, but if you specify a name of a property that does not exist, Select-Object will actually add a property with that name to the object.  String objects have few existing properties, so are a good choice for creating a custom object, an empty string probably being the best bet. Continue reading Creating PowerShell Custom Objects

Generate Exchange Environment Reports using Powershell

As an Exchange administrator, there’s times when it’s useful to have a visual, straightforward and concise document that gives you a good overview of your environment. Although with tools like Visio and Word you can make such a document, it’s hard to keep these documents up to date or use previous versions to track and check changes.

This script, inspired by the output of an Exchange TAP tool, aims to automatically generate a report that gives you an overview of your environment, Exchange 2003, 2007, 2010 and 2013 servers and database availability groups.

Available from: Steve Goodmans’s Exchange Blog