Bulk Disable Mailboxes in Exchange 2010

In a recent post, I wrote about performing a bulk export of mailboxes from a collection (https://deangrant.wordpress.com/2013/10/08/bulk-export-of-exchange-mailboxes-from-a-collection/), now that I have performed the bulk export I am looking to disable to the mailboxes using the same collection list.

I will load the collection of mailboxes from a CSV file using the get-content cmdlet to get the content of the file (\\Server\Share\Mailboxes.csv) which contains the alias name of the mailbox.

$Mailboxes = Get-Content "\\Server\Share\Mailboxes.csv"

Now that we have loaded a collection of mailboxes, we will run a script block to disable each mailbox.

ForEach ($Mailbox in $Mailboxes)
Disable-Mailbox -Identity $Mailbox -Confirm:$false

Set Extension Attribute value for bulk users in Active Directory

I was recently reminded of a powershell script I compiled many months ago, to set a specified extension attribute to the location of JPEG a on a network share which would be used as the users profile picture within Sharepoint.

The script was dependant on two items. Firstly,  the cmdlet’s require ActiveRoles Management Shell for Active Directory to be installed and the filename of the JPEG file is required to match the username of each user.

As mentioned previously, the script is dependant on the installation of ActiveRoles Management Shell for Active Directory being installed and therefore, we need to load the snap-in to the current session

# Adds the Quest.ActiveRoles.ADManagement snap-in to the current session.
Add-PSSnapin Quest.ActiveRoles.ADManagement

The script will require a number of variables to be specified for the UNC path of the shared folder where the JPEG files are located ($UNC) and  the canonical name of the object in the domain to retrieve user objects ($SearchRoot). In the below examples the UNC path is \\Server\Share\ and the domain object is the ‘Users’ organisational unit located in the domain ‘domain.local.

# Variables required to be completed for UNC path of shared folder and canonical name of domain object
$UNC = “\\Server\Share\”
$SearchRoot = “OU=Users,DC=domain,DC=local”

The script will then invoke the command to retrieve all users in the top level organisational unit and set this as a variable.

# Retrieve all users in the organisational unit and stores them in a variable
$Users = Get-QADUser -SearchRoot $SearchRoot

For each item returned in the loop, the script firstly determines if the JPEG file exists on the network shared folder and then if this does, sets the extensionattribute2 to be the UNC path.

# Provides a loop on each item stored in the variable.
foreach ($User in $Users)
# Determines if the profile picture exists for the user.
If (Test-Path ($UNC + $User.SamAccountName +”.jpg”))
# If the profile pictures exists, the extensionattribute2 value is changed for the user account.
Set-QADUser -Identity $User.Name -ObjectAttributes @{“extensionattribute2″=”” + $UNC + $User.SamAccountName + “.jpg”}

The above methodology can be applied for modifying any attribute value within Active Directory, not just my example. Also, the above was compiled in a Windows 2003 domain where the ‘Active Directory Module for Windows PowerShell’ was not available so by using the cmdlets loaded by this snap-in, the dependency on ActiveRoles Management Shell for Active Directory can be removed.