Gary's $this and that about PowerShell

I am a Microsoft Senior Premier Field Engineer based out of Atlanta, GA. My focus is Powershell. This blog is mainly to share interesting Powershell script samples.

Browse by Tags

Related Posts
  • Blog Post: Some Handy Exchange Mailbox and Database Size Powershell One-Liners

    I wrote this up a while ago to share with customers and colleagues, but I never really posted it anywhere. If you look at my previous post about using add-member, you might wonder why then I am using select-object here to create calculated properties which changes the pipeline to PSCustom objects...because...
  • Blog Post: Sample for Sending Email with PowerShell

    I get asked quite often to show examples of sending an email from Powershell.  This could easily by written into an actual cmdlet, and it wouldn't shock me a bit if it already has.  Either way, its very simple .Net code to send email. In this script sample below, I am showing a small utility...
  • Blog Post: Do Your Own Thing - Creating a New Object from Scratch in Powershell V1 to Populate and have your Script Output a nice Object Instead of just Strings

    I use PSObject all the time.  Now when I write scripts I nearly always output an object and unless I can just add to an existing type that is close, I create my own.  I copied from one of my recent ones below to show how I do it.  Now this isn’t a complete script.  $arrobjects would...
  • Blog Post: Simple Text Parse with Powershell using IPConfig.exe

    Here is a fun little one-liner in Powershell: PS C:\> ipconfig | where-object {$_ -match "IPv4 Address"}    IPv4 Address. . . . . . . . . . . : 1.2.3.4 This gets us just the lines from the IPConfig that list the IP address.  This isnt text parsing, this is just filtering the...
  • Blog Post: Example for Identifying Domain Controller Subnet Membership with PowerShell

    First of all let me thank Rich Doyle (a fellow PFE) for allowing me to post this script.  Rich writes some pretty kick-butt stuff and I know I speak for many of us that appreciate his help and his scripts! Now Rich claims he hacked this together and didn't get around to polishing it up with optimization...
  • Blog Post: One-Liner to List Calendar Appointments with a Simple Filter

    So this post is born out of my playing with writing a script to help me be a better PFE.  I need to automatically create calendar appoints to remind me to get all my PFE “paperwork” in on time.  my colleagues will know what I am talking about when I say my TRs.  My thought was to simply...
  • Blog Post: List Mailbox Sizes for both Exchange 2003 and Exchange 2007

    This is a script I put together because…well I don't remember what prompted me to write it.  Who cares :) This script uses the built-in cmdlets for Exchange 2007 find 2007 servers and legacy servers.  It then uses WMI to talk to the legacy servers to get the mailbox sizes.  Technically...
  • Blog Post: Create Calendar Appointments Automatically Based on Existing Calendar Appointments - For my Fellow PFE Co-Workers (The Concepts are for Anyone)

    Like my other PowerShell blog posts, this is a sample of what a script can do.  This post is really meant for my PFE co-workers.  I posted recently about using Outlook to simply list out calendar appointments with a basic filter.  I finally had some time today during travel to Chicago...
  • Blog Post: Lesson Learned Today about PowerShell’s .Net Type System

    Today I was asked why this person saw more properties showing with a “format-table”, than with a “format-table *”.  I will admit, I wasn't sure.  I kicked myself later once I got the answer and I realized I should have known this.  There is a PFE colleague of mine that always seems to...
  • Blog Post: Simple Random Number Demonstration Script

    I was delivering my session today at the Alpharetta (Atlanta) PFE Technology Day, and needed to come up with a good way to give away a free book to the class.  Right before class I threw a little script together to use the random number capabilities of PowerShell.  The script is below:  ...
  • Blog Post: Upcoming Atlanta-Area PowerShell Event

    Hey folks, I am like the Dos Equis guy. I don't post often, but when I do, its about cool stuff :) Yours truly is going to be delivering two sessions at the upcoming PowerShell Saturday event at the Microsoft Office in Alpharetta. It should be a blast, and went really well in Ohio (Columbus) and North...
  • Blog Post: Creating a PS Credential from a Clear Text Password in Powershell

    Before I begin here, let me say, this is very unsecure.  There are very few times when doing this would be a good idea from a security standpoint.  That being said, it is definately possible. First things first.  We need to build a secure string for the password: PS C:\> $password ...
  • Blog Post: Get Exchange Mailbox Database Size – One-Liner – Version 2

    In my previous post ( Some Handy Exchange Mailbox and Database Size Powershell One-Liners ), I introduced a handy one-liner for looking up current mailbox database sizes.  In Exchange 2007, the physical size of the database file isn't listed when you run a cmdlet like “get-mailboxdatabase”. ...
  • Blog Post: Counting Public Folder SubFolders

    This sample script was written by a brilliant fellow PFE named Chris Schrimsher.  Chris gave me permission to post this script out there to the two of you reading my posts…you know who you are :) In this script there is a concept that he is using that I like.  He uses a hash table (dictionary...
  • Blog Post: Using Add-Member in a Powershell One-Liner to Create Calculated Properties

    This is one of the live demos I do when I teach class.  Its a slightly advanced concept for some of my students as it deals with object members.  It is actually fairly nice looking code and I love the fact that I can maintain my original object (instead of say changing to a PSCustom object...
  • Blog Post: Quick AD Search Example

    I was emailing with another instructor tonight and wrote a quick snippet to search AD for an object with a particular SID.  This is quick and way too simple for production, but it just shows how easily you can search AD.  This is with Powershell v1 $searcher = new-object system.directoryservices...
  • Blog Post: Using Microsoft's New AD PowerShell Cmdlets

    In the past two weeks I have really started playing with the new AD PowerShell cmdlets from Microsoft. I am really glad these cmdlets are finally here. I will admit though, to get them working in my lab, it was not easy. I cant blame this though on the cmdlets themselves, as my problems stemmed from...
  • Blog Post: So many ways to take care of that poor old cat – Getting a list of just directories in PowerShell

    Such a simple concept…how can we just retrieve a listing of folders instead of files and folders.  Hopefully readers of this post know already that in PowerShell (1 or 2) we use “Get-ChildItem” (many still use the alias “dir”) to retrieve a listing of files and folders.  If you didn't know...
  • Blog Post: Quick Script to Edit a Single Attribute in AD on a Single User Account

    There are no real dependencies for this script, PSv1 or v2, no snap-ins, no modules….just plain old PS (POPS :) ).  No magic happening here, just some basic read-host and ADSI in play.  I wrote it for a colleague and thought I would share. #This will probably only work for strings and simple...
  • Blog Post: PowerShell and Kinect for Windows

    I put together a script that will allow you to render skeleton joints right in your PowerShell console window.  Kinect sees the skelton and the PS processes it.  The code isn't really polished yet so I am not ready to post it, but here is a little youtube video example of what it looks right...
  • Blog Post: Demo of PowerShell Pipeline Behavior – Asynchronous vs. Synchronous

    When I teach PowerShell classes I sometimes get into a discussion on the more advanced topic (at least for a beginner class) of pipeline behavior in terms of running multiple elements of a pipe synchronously or asynchronously.  I usually have a tough time demo’ing this in a really meaningful way...
  • Blog Post: Find Expiring Certificates Using PowerShell – One-Liner and a Script

    This code is not really complicated at all.  Just the same it can come in very handy, and some folks have never played with the Certificate provider.  I have provided a one-liner version of this code, and a script version.  They are basically the same, but certainly the script one is considerably...
  • Blog Post: Simple but Handy Functions – Part 1 (The Functions Themselves, Detail About Them Coming Soon)

    I thought I would share a few simple functions that I find handy.  They are nowhere near rocket science but still worth it.  I think they would make a nice addition to your PowerShell profile so they are available each time you load PowerShell. function Get-IP {ipconfig | where-object {$_ ...
  • Blog Post: The Get-MailboxStatistics Cmdlet, the TotalitemSize Property, and that pesky little “b”

    In my experiences with Exchange and Powershell, I have definitely come across some interesting things. One of strangest…or so I thought…was the fact that whenever I looked at mailbox size it had a funny little “b” at the end and seemed to be in bytes. That little “b”...