Connect to Office 365 Using a PowerShell Function

by Bharat Suneja on February 16, 2012

When you sign-up for Exchange Online (or Office 365, which includes Exchange Online), an Exchange organization is created for you in Microsoft’s datacenter.

One of the really cool things about Exchange Online is that besides its easy-to-use web interface, you also have the ability to manage your cloud-based organization using PowerShell. Shell-savvy administrators can run Exchange Management Shell commands against the service. This gives you unprecedented remote management capabilities for your cloud-based organization. If you’re connecting your on-premises Exchange Organization to your cloud-based organization in what’s known as a hybrid topology, you can seamlessly manage your on-premises and cloud-based organizations from the Shell.

You don’t need to have any Exchange management tools installed on your computer when connecting to Exchange Online or an on-premises Exchange server using a remote PowerShell session. All you need is Windows PowerShell 2.0 and Windows Remote Management (WinRM), which are installed by default on Windows 7 and Windows 2008 R2.
 
Still on an older OS? You can install Windows PowerShell and WinRM on Windows XP SP3, Windows 2003 SP2, Windows 2008 SP1 and Windows Vista SP1 or later – see Install and Configure Windows PowerShell.

For details about managing your cloud-based organization using the Shell, see Connect Windows PowerShell to the Service. It includes a set of commands you can use to connect to the PowerShell endpoint in Exchange Online. You can save the commands with in a PowerShell script (simply copy them to notepad or other text editor and save the file with a .ps1 extension) and connect to your cloud-based organization with a single-click.

I find it even more convenient to add it as a function in my PowerShell profile. It allows me to connect to Exchange Online using a single command which can be completed using tab completion in the Shell.

  1. Open your PowerShell profile. The default path is C:\Users\<user name>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1. To determine your profile path, you can also type $profile in a PowerShell session.

    A PowerShell profile file is not created by default, but the $Profile variable still provides you the path where it expects the file to reside. If you’ve never created a PowerShell profile, you can fire up Notepad or your favorite text editor (my favorite is Notepad++), paste the function from the next step and save the file as Microsoft.PowerShell._profile.ps1 in the default path returned by the $Profile variable.

  2. Paste this code at the bottom (or anywhere in the profile file but not within an existing function)

    function EXO {
    $LiveCred = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
    Import-PSSession $Session
    }
    function noEXO {Get-PSSession | ? {$_.computername -like “*.outlook.com”} | remove-pssession}

Now start a new PowerShell session and type EXO (you can also type the letter e and use tab completion), enter your Exchange Online credentials and in a few seconds you’ll be managing your cloud-based organization.

When you’re done, type noEXO to terminate the session.

{ 2 comments }

Script: Save all Internet Explorer tabs as Favorites

by Bharat Suneja on January 6, 2012

We spend a lot of time in web browsers and if you’re like me, you probably have a gazillion tabs open – your work stuff, your social media sites, sites for e-learning, e-banking, e-commerce, a few blogs, publications and news sites, sites you’re trying to quote material or save useful tidbits from. Suddenly, the browser window freezes or the whole user experience deteriorates to a point where you can’t work any more. This happens regardless of the browser you use – Internet Explorer, FireFox, or Chrome, all of them are equally suseptible to the deteriorating browser-session-from-hell.

Welcome to the cloud!


Avoiding restarting because you have too many browser tabs open?

Or maybe you just updated your computer (or IT pushed out a bunch of updates) followed by the inevitable Restart your computer to finish installing updates message and you’ve hit the Postpone button enough number of times (asking Windows to remind you in 4 hours each time) that the guilt’s really weighing you down. Time to restart, procrastinator!

When closing or restarting the browser-session-with-gazzillion-tabs, you must determine if you’d like to open all the sites in the next session. Browsers do offer to open web pages from your previous session, but the experience has been less than efficient and the feature only works when you restart after a browser crash. In most cases, you’re not sure if you want to open all or any of the pages from the session (and FireFox allows you to select the tabs to reopen after a crash), but you want to store the links temporarily till you have time to decide.

At times like these, I’ve often wished that browsers would offer to save all of my open pages as favorites/shortcuts in a temporary folder and place it on my Favorites/Bookmarks/Shortcuts toolbar that’s always visible. When I restart the browser and have the time, I can take a look at the folder and go back to any pages I may want to or simply file the favorite in the right folder so I can find it later.


Figure 2: IE allows you to save all tabs from the current window

Luckily, Internet Explorer does have this feature. In the Favorites menu, you’ll find the Add current tabs to Favorites… option. But it comes with one serious limitation – it only adds tabs from the current browser window. If you have multiple windows open, as I do all the time, you’d have to go through this routine multiple times.

Script: SaveIETabs.ps1

Here’s a Windows PowerShell script to accomplish exactly this.

  1. Internet Explorer’s Favorites are stored in the Favorites folder in your home directory (by default, C:\users\<username>. Links that show up on the Favorites bar are in a folder called links. The script creates a Temp folder in it.
  2. Creates folder with today’s date
    1. Checks if a sub-folder named IE-<today’s date> exists in the Temp folder
    2. If the folder exists, it appends a number to the new folder name (so it becomes IE-<today’s date>-X, where the number X is incremented for each iteration until the folder name check is false)
  3. Grabs the URLs from all open Internet Explorer tabs
  4. Removes any special characters from page names
  5. Saves them as shortcuts in the folder.

End-result: When you restart Internet Explorer, you can click on Temp > IE-date folder, you can see a shortcut for all pages that were open before you restarted the browser.


Figure 3: The script saves all open web pages in a Temp folder on your Favorites toolbar in Internet Explorer

Download: SaveIETabs.ps1 (zipped)
Version: 1.1
Date: 12/20/2011

Usage:

SaveIETabs.ps1
-Add – adds all tabs as Internet Explorer favorites
-Full – spits out tabs as hash table that can be manipulated in PowerShell
-Location – outputs name and url
-Content – Retrieves title, URL and content (text in page body)

Alt.misc

I didn’t have to write the SaveIETabs.ps1 script from ground up – thanks to a script Alex Angelopoulos wrote. Alex’s version can save all URLs to a text file and reopen them from the saved file next time you start IE. I’ve modified it to save the tabs as IE Favorites and added some usability enhancements.

Some web pages don’t have a title, in which case the URL is used as the page title or has special characters in the page name. This works when displaying in IE and other browsers, but it’s an issue when trying to use it as a file name. Files don’t like to have special characters in their names (although they make an exception for dashes, underscores, dots and spaces). The script parses the file name before saving it and removes any special characters if it finds them.

The fun part was doing the string manipulation using regex, one reason I love the .NET regex implementation (and would like to see support for it in Exchange’s Transport Rules, Exchange Search and Discovery features). See .NET Framework Regular Expressions on MSDN for details.

On the browser wishlist

While on the subject (Hello Internet Explorer and Mozilla FireFox teams!), why don’t the Favorites/Bookmarks bars or menus have a search box? Given we now have a gazillion pages bookmarked, a way to quickly search our favorites – not the entire web, for the web page we’re looking for would be great. There are browser plug-ins and cloud-based services to make managing bookmarks easier, but managing plug-ins (and using cloud services for bookmarks) is another story altogether.

The functionality should be available out-of-the-box in current browsers.

{ 0 comments }

iPhone and the myth of a 2-year contract with AT&T

October 14, 2011

Windows Phone 7.5 (‘Mango’) is now available to all customers, a remarkably quick and smooth update this time around. The Windows Phone team has proved it’s learning how to handle updates and work with the number of Windows Phone device manufacturers – Acer, HTC, and Samsung to name a few, and carriers across the world. [...]

Read the full article →

Microsoft to release PST Capture tool to search, import and destroy PST files

July 5, 2011

Microsoft has announced it will release PST Capture, a free tool to search .PST files, import them into Exchange Server 2010 and Exchange Online and (optionally) destroy the files. Exchange mailbox data is stored on Exchange servers – either on-premises in your organization’s datacenter, or in Exchange Online if you’re using Microsoft’s new Office 365 [...]

Read the full article →

Installing Windows from a USB Drive, recovery partitions and TRIM support

February 28, 2011

USB flash drives have been a welcome development for computer storage — they offer a great alternative to optical drives (aka CD/DVD drives). The form factor makes them easy to carry around, they’re faster than optical drives, and you can rewrite/reuse them as many times as you wish. They’re also more reliable than optical media. [...]

Read the full article →

Cisco’s failure as a hosted email provider

February 24, 2011

Cisco entered the hosted email business thirteen months ago. Don’t blame yourself for not knowing about Cisco Mail — many experts were similarly unaware till earlier this week, when Cisco announced it’s quitting the business. Debra Chrapaty, Vice President of Cisco’s Collaboration Software Group (formerly Corporate Vice President of Global Foundation Services at Microsoft), notes [...]

Read the full article →

UDP notifications support back in Exchange 2010, Outlook 2003 users rejoice

January 31, 2011

If there is a legacy client for Exchange 2010, it must be Outlook 2003. Released in October 2003, Outlook 2003 is two versions and almost eight years old! When running in online mode, Outlook 2003 relies on Exchange Server to notify it of new messages by sending UDP notifications. If UDP notifications aren’t received, Outlook [...]

Read the full article →

Redmond Mag: 10 Best Things Microsoft Did In 2010

January 11, 2011

If you’re too focused on Exchange Server and Windows infrastructure, it’s easy to miss some of the other remarkable products and services Microsoft released in 2010. Doug Barney lists the 10 Best Things Microsoft Did In 2010. Not surprisingly,

Read the full article →

Happy New Year, You Just Won a Gazillion Dollars!

January 3, 2011

With the end of holidays comes the beginning of a new year, and this year a new decade. I’ve had a longer semi-vacation in December, and I’m looking forward to the promise of an exciting 2011. The part that I least look forward to is all the Christmas/New Year spam, some of which inevitably makes [...]

Read the full article →

Exchange Server 2010 Inside Out, and do technical books still matter?

December 15, 2010

After tech-reviewing a few books and coauthoring Exchange Server 2007: The Complete Reference, I’ve shied away from writing another technical book. It’s an intense effort, and much more time-consuming than one can possibly imagine without actually having done it. And if you’re a fanatic about technical accuracy, and strive to provide more technical depth than [...]

Read the full article →