Create Shared Mailboxes with CSV and PowerShell


For the purpose of creating Shared Mailboxes in Office 365/Exchange Online I created a PowerShell script which uses a CSV file for input. The file must be saved as “Unicode, Semicolon separated” (;) and must contain the following fields:

Name Description
Name Name of the Shared Mailbox (this field cannot contain spaces!)
Display Name Full / Display Name
Email Primary email address (this field can contain only one address)
Alias Email alias address(es) – when using more than one: separate them by using a comma (,)
Members Specify the primary email addresses for users who will have access to this mailbox – separate them by using a comma (,)

During the process of creating Shared Mailbox(es) the script creates a security enabled Distribution Group with the name SG_”SharedMailbox Name”. This Distribution Group is given full access to the mailbox. So when a user needs access to the group they only have to be a member of the Distribution Group. Make sure that you give the right people (normally the IT department) owner rights for this Distribution Group. Because only owners can add members to the group. You need to specify the primary email addresses for the owners in the PowerShell script! Separate the email addresses by using a comma (,)

Script

Here’s the code for the script:

#### Set Variable
Set-Variable -name Domain -value wortelltechready.com
Set-Variable -name DGOwners -value admin@wortelltechready.com,user1@wortelltechready.com
#### Create Function Logon to Office365 - Exchange Online
function Logon {
 #### Pop-up a dialog for username and request your password
 $cred = Get-Credential
 #### Import the Local Microsoft Online PowerShell Module Cmdlets and Connect to O365 Online
 Import-Module MSOnline
 Connect-MsolService -Credential $cred
 #### Establish an Remote PowerShell Session to Exchange Online
 $msoExchangeURL = “https://ps.outlook.com/powershell/”
 $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $msoExchangeURL -Credential $cred -Authentication Basic -AllowRedirection
 Import-PSSession $session
 }

#### Create Function Logoff Office365 & Exchange Online
function Logoff {
 #### Remove the Remote PowerShell Session to Exchange Online ----
 Get-PsSession | Remove-PsSession
 #Remove-PsSession $session
 }

############################################################################################################################
############################################################################################################################

#### Logon to Office 365 & Exchange Online
Logon
#### Ask the user for input CSV File
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$ofd = New-Object System.Windows.Forms.OpenFileDialog
#$ofd.InitialDirectory = "d:\scripts"
$ofd.ShowHelp=$true
if($ofd.ShowDialog() -eq "OK") { $ofd.FileName }
$File = $ofd.Filename

#### Create Log File + Start Logging
if ($File -ne $Null) {
$Log = $File + ".log"
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path $Log -append
 }

#### Import CSV
Import-csv -Delimiter ";" $File | ForEach {

#### Create Mailbox
New-Mailbox -Name $_."Name" -DisplayName $_."Display Name" -PrimarySmtpAddress $_."Email" -Shared

#### Set Mailbox Size for Shared Mailboxes
Set-Mailbox $_."Name" -ProhibitSendReceiveQuota 5GB -ProhibitSendQuota 4.75GB -IssueWarningQuota 4.5GB -MicrosoftOnlineServicesID $_."Email"

#### Add Aliases
$Aliases = $_.Alias -split ','
if ($Aliases -ne $Null) {
 Set-Mailbox $_."Name" -EmailAddresses @{add= $Aliases}
 }

#### Create Security Group with name SG_"Distribution Group Name", add Members and set Owners
$Name=$_."Name"
$DGName="SG_" + $Name
$DGMail=$DGName + "@" + $Domain
New-DistributionGroup -Name $DGName -Type Security -PrimarySmtpAddress $DGMail
$Member = $_.Members -split ","
$Member | Foreach-object {
Add-DistributionGroupMember -Identity $DGName -Member $_
 }
Set-DistributionGroup $DGName -HiddenFromAddressListsEnabled $true
Set-DistributionGroup $DGName -BypassSecurityGroupManagerCheck -ManagedBy $DGOwners
#### Add permissions for Distribution Group
Add-MailboxPermission $Name -User $DGName -AccessRights FullAccess
Add-RecipientPermission $Name -Trustee $DGName -AccessRights SendAs -Confirm:$False

 

}
#### Stop Logging
Stop-Transcript
#### Logoff
Logoff

Copy and paste the code in notepad (for example) and save it as “CreateSharedMailbox.ps1”. Go through the following steps to use the script.

Steps

This is part 2 of a series of posts about some PowerShell scripts I created or used and modified for some Office 365/Exchange Online migrations.

In part 3 of this series I will share a script which can be used to convert Shared Mailbox(es) to Regular Mailbox(es).

An overview of the series can be found here.

Download a sample CVS file from here: CreateSharedMailbox.csv. After the download, rename the file to “CreateSharedMailbox.csv”.

Advertisements
Create Shared Mailboxes with CSV and PowerShell

Office 365 / Exchange Online PowerShell Scripts – part 1


At my first real confrontation with Office 365 and Exchange Online (about 7 months ago) I was really surprised by the fact that there are so little complete PowerShell scripts out there.

So with the help of my basic PowerShell knowledge (at that time) and my favorite search engine (no names here J) I build some scripts that we used for some big migrations to Office 365/Exchange Online.

This is the first post in a series where I will discuss every script I created or used and modified in a separate post.

In this fist post I’d like to share a way to create a function and adding it to your PowerShell profile so that you can quickly execute the function from any open PowerShell session when you need it.
I came across the following post from Thomas Ashworth: http://blogs.technet.com/b/thomas_ashworth/archive/2012/04/11/connect-to-office-365-via-remote-powershell.aspx and added a section for connecting to Office 365 in one command. So the information in this post is based on the post of Thomas.

Start by creating a PowerShell profile if you do not already have one. The following one liner will create an empty PowerShell profile.

New-item $profile –itemtype file –force

Next open the profile file in Notepad. This step is easily performed from PowerShell using the following command.

Function Connect-ExchangeOnline


{
[CmdletBinding()]

param

(

[Parameter(Mandatory = $False)]

[System.Management.Automation.PsCredential]$Credential = $Host.UI.PromptForCredential(“Enter MSOL Admin Credential”,

“Enter the username and password of an MSOnline Administrator account.”,

“”,

“userCreds”),

[Parameter(Mandatory = $False)]

[System.Uri]$Uri = “https://ps.outlook.com/powershell/"

)

Import-Module MSOnline

        Connect-MsolService -Credential $Credential

        $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $Uri -Credential $Credential -Authentication “Basic” -AllowRedirection

Import-PSSession $session -AllowClobber

Return $session

}

From now on whenever you need to connect to Office 365 and/or run Exchange cmdlets, you can simply type “Connect-ExchangeOnline” directly at the PowerShell prompt.

In part 2 of this series I’ll share a script which creates Shared Mailboxes + security group and adds the appropriate members.

Office 365 / Exchange Online PowerShell Scripts – part 1

Connect Azure to App Controller


Ever wanted to try out the integration of your On-Premise Hyper-V virtual infrastructure and Azure? Here are the steps how to do this.
You need to have System Center Virtual Machine Manager 2012 and App Controller with SP1 (Beta) in place. The installation of these will not be discussed.

Create an Azure subscription

The first step is to create a 90-day trial subscription on Windows Azure: http://www.windowsazure.com/en-us/pricing/free-trial/

Activate VM Preview Feature

Log in to the Azure portal (https://account.windowsazure.com/PreviewFeatures) and activate the “Virtual Machines & Virtual Networks” Preview Feature:

Create certificate

On the App Controller server open the IIS Management Console and create a Self-Signed Certificate.


Export certificate

Export the certificate two times. Once in PFX format (with the private key) and once in CER format (without the private key).
The PFX is used for App Controller and de CER is used for Azure.

Import certificate

First import the certificate in Azure.
Go to the Azure management portal: https://manage.windowsazure.com/ and go to Settings:

Click on Upload:

Browse for the .CER certificate:

Now make sure that you can copy the whole Subscription ID. Expand the column:

And copy the whole ID into you clipboard:

Now import the certificate (PFX) in App Controller. Open the App Controller portal, go to Clouds and click on Connect, Windows Azure Subscription:

Fill in the necessary fields, paste the Subscription ID, browse for the .PFX certificate and fill in the password you used when exporting the certificate.

That’s it: from now on you will be able to manage and create you’re VM’s in your on-premise environment and you’re Azure subscription.

One problem I ran into when connecting Azure in App Controller, I got the error message:

This was because the “App Controller Windows Azure Provider” service was not running on the App Controller Server.

Connect Azure to App Controller