Code

Bulk import PST files – [updated] v1.1

Bulk import PST files – [updated] v1.1

Just wrote a basic script for importing PST files into mailboxes, that I want to share with the community.

It is designed to check for PST files in the specified folder. Based on the filenames (of the PST files) it then verifies that a mailbox can be found. This is done by using the filename and adding the @ character and the domain value into a string value. If there is a match, it returns a value of $True and the script continues with running the New-MailboxImportRequest cmdlet.

The script is written just as basic as it can, it provides much information about values and what’s going on.
The most recent updated script can be downloaded here

I hope this will help you to import the PST files into the mailboxes

Ps. Sorry for the word-wrap, see the script file instead of copy the script code below

Changelog
v1.1
– Updated the $name variable due to issues with filenames got trimmed away. Also added so that if errors exists, they will be sent to a errorlog. Thanks to Chris Steding!

# +=======================================================================
# | Blog: http://www.testlabs.se/blog
# | Twitter: @jonand82
# | =============================================
# | Filename: Import-PST v1.1.ps1
# |
# | CREATED BY: Jonas Andersson
# | FUNCTION: Imports PST files into mailboxes, matching on emailaddresses
# |
# | CHANGE LOG: 
# | v1.0 - 2013-09-18, *Created*
# | v1.1 - 2013-09-22, *Update of $name variable*
# |
# |    Required permissions (RBAC) Role: “Mailbox Import Export”, example: New-Managementroleassignment –Role “Mailbox Import Export” –User “Administrator”
# +=======================================================================

# Load snapin
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction 'SilentlyContinue'

# Variables
$error.clear()
$errorlog = "C:\temp\errorlog.txt"
$pstpath = "C:\temp"
$domain = "testlabs.se"
$servername = "tlex01"
$files = Get-ChildItem -Path $pstpath -Filter *.pst

Write-Host $files

if (($files -ne $null) -or ($files -eq "")) {

    foreach ($i in $files) {

        $name = $i.BaseName
        $id = $name + "@" + $domain
        $filename = $i.FullName
        $filename = $filename.Replace(":","$")
        $uncfilepath = "\\" + $servername + "\" + $filename

        Write-Host "#################################################################"
        Write-Host "Filename:" $i -ForegroundColor 'Cyan'
        Write-Host "UNC path:" $uncfilepath -ForegroundColor 'DarkCyan'
        Write-Host "Emailaddress:" $id -ForegroundColor 'DarkGreen'

        $MailboxExists = [bool](Get-Mailbox -Identity $id -ErrorAction SilentlyContinue)

        if ($MailboxExists -eq $false)
        {
            Write-Host "Found mailbox:" $MailboxExists -ForegroundColor 'Red'
            Write-Host "Make sure to match filename to mailaddress, without @domain" -ForegroundColor 'Red'

        }

        if ($MailboxExists -eq $true)
        {
            Write-Host "Found mailbox:" $MailboxExists -ForegroundColor 'Green'
            Write-Host "Importing $uncfilepath into mailbox: $id" -ForegroundColor 'White'

            New-MailboxImportRequest -Mailbox $id -FilePath $uncfilepath

        }

        Write-Host ""
    }

}

else
{
    Write-Host "No PST files found"
}

if ($error -ne $null)
{
    $error | Out-File -FilePath $errorlog -Append
    Write-Host "See $errorlog for errors" -ForegroundColor 'Red'
}
Author of a book – PowerShell cookbook

Author of a book – PowerShell cookbook

If you have missed the news on my twitter, I can tell you that the last 6 months I’ve been busy with writing a book called “Microsoft Exchange 2013 PowerShell Cookbook: second edition” for Packt Publishing.

That’s also why the blog not have been updated that much lately, now it’s time to startup with the activities for the online community work again since the book more or less is completed. Just doing the final updates of the chapters. I want to thank both Anderson Patricio [MVP] and Marcelo Vighi [MVP] for doing a great job with the review.
I also want to send a special thank you to Magnus Björk [MVP] for helping me out when bugs were found.

It have been a great experience doing this project, both exciting and exhausting in the same time because of high tempo and tight time schedules. But I can recommend everyone that thinking of doing this kind of job, DO IT!

You might wonder when it will be released? mid June..

9427EN_MockupCover_Cookbook

More info about the book can be found here:
http://www.packtpub.com/microsoft-exchange-server-2013-powershell-2e-cookbook/book
http://www.amazon.com/Microsoft-Exchange-PowerShell-Cookbook-ebook/dp/B00BP47WHE/ref=sr_1_1?s=digital-text&ie=UTF8&qid=1364252267&sr=1-1

And some information about me:
http://www.packtpub.com/authors/profiles/jonas-andersson

C#.NET – Configure Exchange 2010 Tool

C#.NET – Configure Exchange 2010 Tool

======

Updated the code again, this time a minor bug in code.
Version is now 0.93.

======

Thanks to John A Cook @JohnACook, who found the issue. It’s now resolved, the tool is now updated and working in my lab environment.
It was a compilation issue, found out that it was compiled as a x86 tool. Sorry for that folks! Thanks a lot for helping me out

======

Download

ChangeLog:
0.93 – Updated minor bug in code
0.92 – Fixed the compile issue.
0.91 – The tool has now been updated to version 0.91, this update fixed if URL’s was not configured/null.

Description:

A while ago I was having this idea of creating a tool that configure the most common things on the Exchange server(s).

It took about 3-4 weeks to complete the application with all coding, which includes around 3000 lines in total.

The tool should be used locally on the server, since it’s using the Exchange PowerShell snapin when doing the query’s and configuring parts.

Besides the smaller parts that uses PowerShell the application is built on C#.NET.

Before going into detail, at the moment it’s version 0.9 since I’m about to optimize the code a bit more. I will update the blog post when it’s done.
Until then, use it as much you want and feel free to give any feedback (it’s great to get feedback).

The debugging of the application has been done on Exchange 2010 SP2, that’s the version it’s built for. But most likely it will work on RTM newer.

Description:

The tool will give you the opportunity to configure the following Exchange features:

Autodiscover, Outlook Web App, Active Sync, Web Services, Control Panel, Offline Address Book, POP/IMAP and Outlook Anywhere.

Check the screenshots below:

imageimageimage

All functions are built upon a query is done first and then it’s possible the change the current settings using the “Set” button.

The first tab is for configuring the Autodiscover SCP settings (Get-ClientAccessServer).
Press the Query button for requesting the current setting, and then you’re able to change it by editing the text and press “Set” button.

The second tab it for set the Internal and ExternalUrl for Outlook Web App, and also for the Logon format.

Third tab is used for Exchange ActiveSync, it’s possible to set the Internal and ExternalUrl and also set the Basic Authentication setting.

Fourth tab is for Exchange Web Services, Internal and ExternalUrl is about to be configured.

Fifth, Exchange Control Panel settings; Internal and ExternalUrl.

Sixth, Offline Address Book settings; Internal and ExternalUrl.

Seventh, POP and IMAP settings, it’s possible to change the Logintype, X509 name and set the Service to Automatic and Start it.

Eighth and final tab, Outlook Anywhere configuration, External hostname and what authentication setting is possible to change here.

About tab, it speaks for it self. Information about the small application

Note: The first query take some time, since it’s loading the snapin. Have some patience, but after the first one it should be pretty fast.

Download the application from here

Like I initially said I will do some code optimization, and will be updating this blog post when it’s done.
Feel free to leave comments, it’s always a pleasure to read them!

Ps. Use the application/code/scripts at your own risk. Test in lab environment first.

Thanks for reading

C#.NET – Create Mailboxes

C#.NET – Create Mailboxes

Updated:

Version 1.0.1 is released

I’ve added the possibility to create Room, Equipment and Shared Mailboxes.
The zip file with the application is now updated, one CSV example file is included.

=====

This is my 3rd C#.Net application, this one is creating mailboxes based on CSV file (semi colon separated).

I’m using FileHelpers for reading the CSV file, this dll file is embedded into the exe file for easier handle.

The application is using remote PowerShell, so make sure that you have enabled remote PowerShell for the user that’s configured.
Follow this link: http://technet.microsoft.com/en-us/library/dd298084.aspx

The remote PowerShell connection mechanism is the default (Windows Auth) one.

Start with browsing for the CSV file, semi colon separated (;), then press the Load button for loading up the contents in the CSV file.
The items will be counted in the upper right corner.

Next step is to press the Verify button for checking so that the mailboxes doesn’t already exists.
If some of them already exist, the Create button will not be clickable.
If some mailbox already exists, make sure to edit the CSV file and load it again and then hit the Verify button.

When none of the listed mailboxes are found, the Create button will be clickable.

After the mailboxes has been created it will list them with UPN and Status (OK, Created).
If you want to be sure that they were created, press the Verify button for checking if they exist.

(Or search for them using EMC/EMS)

image

Feel free to use the application how much you want, use it at your own risk and I don’t do any kind of support for it.

The application can be downloaded here.
CSV file example is included.

Thanks for reading

Selected PowerShell commands, output to CSV file

Selected PowerShell commands, output to CSV file

Here’s a sample on a basic PowerShell script that combines Get-Mailbox, Get-User and Get-MailboxStatistics commands.

The specified objects will be saved into a CSV file.

You can download the script here.

I would be more than happy for any kind of comment or feedback
Feel free to use the script below


#############################################################################
 # PS-Merge.ps1
 # Description:
 # This script combines three commands and sends the output into a CSV file
 #
 # Jonas Andersson, MCC 2011
 # http://www.testlabs.se/blog
 # Twitter @jonand82
 #############################################################################

#Add Exchange Management Snap-In to recognize Exchange CmdLets in PowerShell
 Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue

$Database = @{Name="Database";Expression={ $stats.database }}
 $DisplayName = @{Name="DisplayName";Expression={ $stats.DisplayName }}
 $StorageLimitStatus = @{Name="StorageLimitStatus";Expression={ $stats.StorageLimitStatus }}
 $TotalItemSize = @{Name="MailboxSize";Expression={ $stats.TotalItemSize }}
 $Company = @{Name="Company";Expression={ $user.Company}}
 $FirstName = @{Name="FirstName";Expression={ $user.FirstName}}
 $LastName = @{Name="LastName";Expression={ $user.LastName}}
 $LastLogon = @{Name="LastLogon";Expression={ $stats.LastLoggedOnUserAccount}}
 $LastLogonTime = @{Name="LastLogonTime";Expression={ $stats.LastLogonTime}}

$Mailboxes = Get-Mailbox -ResultSize Unlimited
 $Mailboxes | foreach {
 $user = Get-User $_
 $stats = Get-MailboxStatistics $_
 $_ | select Alias,SamAccountName,$DisplayName,$FirstName,$LastName,$LastLogon,$LastLogonTime,$Company,*SMTP*,$Database,$StorageLimitStatus,$TotalItemSize,RecipientTypeDetails
 } | Export-CSV -NoTypeInformation C:\output.csv

C#.NET – List all mailboxes

C#.NET – List all mailboxes

Since I promised to put the source code and the application here on the blog, so here it is.

The source code can be downloaded here.

It’s not any kind of advanced application, it lists all mailboxes in the environment it’s connected to.
The connection is done by using Remote PowerShell and can be configured in the Settings tab.

The importance to get the application working is to have Remote PowerShell configured for the connecting user.
And don’t forget if you’re using HTTPS the certificate names needs to be in place, or else it won’t work.

Feel free to use the code and customize it.
Just notify me or have a link the my blog.

There is a barrier before getting started and really learn and understand C#.Net so I want to thank Peter Ericsson, Martin Sundström and Mike Pfeiffer for some kind tips and tricks.
(Press their names for being redirected to their blogs.)

Thanks for your help