Enable New User Mailboxes with PowerShell

Mail enabling new users should be easy to do from within the Exchange management console.  If you are in a really large organization, you soon discover that it is painfully slow.  When we create new users it takes time to replicate to Exchange, so we don’t mail enable new users upon creation.  Making matters worse is that our mail alias isn’t the default for Exchange, which is the UPN.

Enable-NewUserMailboxes.ps1 is a PowerShell script which bulk enables new user accounts, permitting a custom Exchange alias.  For publication I have set this to the SamAccountName, but with a little bit of coding, you can change it to your requirements.

The script runs interactively, and will automatically checks for and loads the remote Exchange shell.  If you have not specified a starting OU for search at the top of the script, you will be prompted to select the OU to query for user accounts.  Then a list of users is collected and display using Out-Gridview:

Capturing output from Enable-Mailbox turned out to be a challenge.  I ended up doing this:

The script creates a logfile, which is placed by default on your desktop. The log folder can be edited.

Script Text
Posted in Alan's Favorites, Exchange, PowerShell, Scripting, Windows Administration | Tagged , | Leave a comment

Drag and Drop Form for Powershell

Get-DragAndDrop.ps1 is drag and drop PowerShell form is based on http://www.rlvision.com/blog/a-drag-and-drop-gui-made-with-powershell/.  All the interesting coding bits were written by Dan.  I modified the script to make it an advanced function which has parameters for the form title, instructions, status and button title.  The default form looks like this:

Screen Capture for Drop and Drag Function

Screen Capture for Drop and Drag Function

Script Text
Posted in Functions, PowerShell | Tagged | Leave a comment

PowerShell Get Column Names for a CSV File

Get-Member doesn’t always show you what is under the hood for an object.  For that you need the .PSObject property.  Here PSObject.Properties contains CSV column names

Posted in PowerShell, Scriptlets | Tagged | Leave a comment

Powershell Date LDAP filters

This snippet can be used for easier date formatting when using an LDAP date filter with PowerShell.  This demonstrates how to get users created within the previous 30 days using LDAP:

 

Posted in Active Directory, PowerShell, Scripting, Scriptlets | Tagged , | Leave a comment

PowerShell Pause with Progress Bar

This snippet of PowerShell was written to have show users something more interesting than “Sleeping for 15 seconds” in a script.  Notice that I splat the progress parameters.

Posted in PowerShell, Scripting, Scriptlets | Tagged | Leave a comment

Fix Creation Date Later than Date Modified with PowerShell

A weird and annoying thing happened to my home directory at work when it was moved from Windows to a storage appliance. The file CreationTime was lost on all the files and was set to the date of the data move. Particularly annoying was seeing the CreationTime being more recent than the LastWriteTime attribute. At one point in my IT career I thought that these attributes could not be changed by the user. I was wrong. In .NET these methods are available using System.IO. Here is the script — you will need to edit some choices a the top to use it.

Posted in PowerShell, Scripting, Scriptlets, Windows Administration | Tagged , , | Leave a comment

OU of Current PC from anywhere in the Forest

There are a lot of ways to get the OU of the current computer, but most don’t work if you are outside your home domain. This code does, without requiring AD cmdlets:

Update: 9/23/2017: You can also get this information with the ADSystemInfo COM object, see Get-ADSystemInfo; Wrapping the ADSystemInfo ComObject.

Posted in Active Directory, Scripting, Scriptlets | Tagged , | Leave a comment

An Empty Pipe Element is not Allowed Here – Workaround

This code gives you the error, “An Empty Pipe Element is not Allowed Here”:

The workaround which solves this problem is to make it an array by enclosing the code in @(), Example:

Posted in PowerShell, Scriptlets | Tagged | Leave a comment

Split a List and Remove Empty Lines with PowerShell

I often have lists where I have to split the list, and remove empty lines.  This is how I do it:

This method uses a regular expression with three different variations of line break, then the .NET method of removing empty lines.

Posted in PowerShell, Scripting, Scriptlets | Tagged | Leave a comment

Create an AD Drive for Specified Domain

When you load the Active Directory Module, you get, by default, an Active Directory PSDrive for the current domain.   You can avoid the drive from loading by setting $Env:ADPS_LoadDefaultDrive = 0. When writing scripts to export and import AD delegations, connecting to this remote drive became important to me. Here is an example of the code I used:

Posted in Active Directory, Functions, PowerShell, Scripting | Tagged , , | Leave a comment