PowerShell – Great for Documentation

Today, I needed to quickly make some documentation for a client to show them how many content databases they have and the total number of site collections that currently exist in their environment. PowerShell came to the rescue beautifully and helped me solve the problem.

First, I wanted to know what PowerShell commands were available to me, so I located a blog post by Adam Preston detailing how to dump all of the commands to a text file. Once you have the commands, you can make use of PowerShell’s Get-Help command to get the syntax and description of the command.

Armed with this, I discovered the Get-SPContentDatabase commandlet that iterates over all the available content databases in the farm. Executing Get-SPContentDatabase without any parameters will return every content database in the farm. However, the list format was not the desired format.

Further research lead me to create my own table format:

$a = @{Expression={$_.Name};Label=”Database Name”;width=70},@{Expression={$_.CurrentSiteCount};Label=”Sites”;width=10}

This format makes sure there is plenty of room for a long database name and then gives the ability to show how many site collections are in the database. Now, my command is:

Get-SPContentDatabase -WebApplication http://mycoolintranet.mycompany.com | format-table $a > ContentDatabases.txt

When the command completes, I can simply open up the text file and begin my documentation.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s