North East Bytes - a Microsoft technology usergroup in North East England.

Tweets

Powered by Squarespace

Tuesday
May132008

Using PowerShell in a Mixed 2003/7 Exchange Environment

Most Exchange admins will have learned, to their distress or delight, that Exchange 2007 has PowerShell at the core of its management. In fact, if you're not aware of that, the GUI seems really odd - you've got to adjust your thinking somewhat and remember it's actually closer to the command line than the old Exchange System Manager. Actually, that was really the catalyst for me getting into PowerShell so much.

Anyway, Exchange 2007 and PowerShell work great together and I wish that I was in a position to take full advantage, but I guess like a lot of people, we're in the process of migrating to Exchange 2007 and will have some Exchange 2003 servers for a while yet. That means that we have our hands tied to a certain extent, but it doesn't mean that we can't do a lot with PowerShell!

The PowerShell function that I've written here is a good example of how you can use the new Exchange 2007 cmdlets to a certain extent and the limitations of that backwards compatiblity. Since we get a lot of requests for quota increases, what I've set out to do is find out the quota limits and current usage when given a username. We also have a slightly strange situation with SMTP addresses (more on that later), so I'm listing those out, as well as the mailbox location...

function get-mailboxinfo ([string]$user = $(Throw "USAGE: get-mailboxinfo username"))
{
$usermb = Get-Mailbox $user
"{0,-15}{1,-2}{2,-20}" -f "User",":",$user
"{0,-15}{1,-2}{2,-40}" -f "Name",":",$($usermb.DisplayName)
"{0,-15}{1,-2}{2,-20}" -f "Server",":",$($usermb.ServerName.ToUpper())
"{0,-15}{1,-2}{2,-40}" -f "Database",":",$($usermb.Database)
"-- SMTP Addresses --"
($usermb.EmailAddresses |?{$_.IsPrimaryAddress -and ($_.PrefixString -eq "SMTP")}|select addressstring).AddressString + " (primary)"
$usermb.EmailAddresses |?{!($_.IsPrimaryAddress)}|select addressstring | %{$_.AddressString}
"-- Quota & Usage --"
if ($usermb.UseDatabaseQuotaDefaults -eq $TRUE){
    write-Host "Using database default quotas"
    $WarningPreference = "SilentlyContinue" #get-mailboxdatabase generates warnings if .edb in a root directory
    #Need to use get-mailboxdatabase in this way to work with Exchange 2003...
    #If only using Exchange 2007, get-MailboxDatabase $usermb.Database is better...
    $mbdatabase = Get-MailboxDatabase -IncludePreExchange2007 -Server $usermb.ServerName | ?{$_.name -eq $usermb.Database}
    $iwq = $mbdatabase.IssueWarningQuota.Value.ToKB()
    $psq = $mbdatabase.ProhibitSendQuota.Value.ToKB()
    $psrq = $mbdatabase.ProhibitSendReceiveQuota.Value.ToKB()}
else{
    $iwq = $usermb.IssueWarningQuota.Value.ToKB()
    $psq = $usermb.ProhibitSendQuota.Value.ToKB()
    $psrq = $usermb.ProhibitSendReceiveQuota.Value.ToKB()}
if ($usermb.RecipientTypeDetails -eq "LegacyMailbox"){
    #Use WMI to find size of Exchange 2003 mailbox
    $filter = "MailboxGUID='{" + $usermb.ExchangeGuid + "}'"
    $wmimb = gwmi -ComputerName $usermb.Servername -Namespace "root\MicrosoftExchangeV2" -Class "Exchange_mailbox" -filter $filter
    $mbsize = $wmimb.size}
else{
    #WMI MicrosoftExchangeV2 namespace replaced by get-mailboxstatistics cmdlet in Exchange 2007
    $mbsize = (Get-MailboxStatistics $user).TotalItemSize.Value.ToKB()}
"{0,-15}{1,-2}{2,7}" -f "Using (KB)",":",$mbsize
"{0,-15}{1,-2}{2,7}{3,8}{4,8}" -f "Quotas",":",$iwq,$psq,$psrq
"{0,-15}{1,-2}{2,7:p}{3,8:p}{4,8:p}" -f "Quota %",":",$($mbsize/$iwq),$($mbsize/$psq),$($mbsize/$psrq)
}

What that will give you, is a quick report like this, irrespective of where the mailbox is:

User : fbloggs
Name : Fred Bloggs
Server : EXSERVER1
Database : Mailbox Store 6
-- SMTP Addresses --
fred.bloggs@yourdomain.com (primary)
fred.bloggs@marketing.yourdomain.com
-- Quota & Usage --
Using (KB) : 385911
Quotas : 500000 600000 1000000
Quota % : 77.18 % 64.32 % 38.59 %

You may not find the SMTP address list so helpful, but our users each have four (and an X400 address) like:
username@theexchangesystem.domain.com (initially set as the primary by the recipient update policy)
username@forestrootdomain.domain.com
emailname@shortdomain.com (external address with abbreviated domain name, so most used)
emailname@longdomainname.com (the primary external formal email address)
so you can see how it's useful in our case!

If you want to take advantage of Exchange 2007 and the extra info that you can easily get about those mailboxes, add this into the function and wish that migration would move a little faster...

if ($usermb.RecipientTypeDetails -eq "UserMailbox")       
    {get-MailboxStatistics $user | FT ItemCount,StorageLimitStatus,@{label="TotalItemSize (KB)";expression={$_.TotalItemSize.Value.ToKB()} },LastLogonTime -auto
    write-Host "Largest folders for $($user):"
    get-MailboxFolderStatistics $user | Sort foldersize,folderpath -desc | Select-Object -first 10 | FT FolderPath,ItemsInFolder,@{label="FolderSize (KB)";expression={$_.FolderSize.ToKB()}} -auto
    }

Monday
May052008

Xobni Launches

I mentioned 3rd-party Outlook add-in Xobni a while ago, and have been using the beta since then. I received an email from them today announcing the general availability of the product. The launch is accompanied by a New York Times article only a few days after Xobni appeared on Georgina's TechNet blog - I wonder how many start-ups can claim both of those accolades for their new product?!!

I haven't particularly used Xobni as a search tool as I'm happy with the results from Outlook 2007's own search, but I do like a few things about it. I find the at-a-glance access to recent conversations and attachments shared with a contact handy, and also the way the sidebar changes to show your most recently viewed message when you change your view to the calendar (it's very useful when that message is asking for a meeting, causing you to consult the calendar). Even if you don't want to take up screen real estate with the sidebar, in its collapsed form it provides more useful information than Outlook's own To-Do bar (in collapsed mode), which I used to use. I'm sure that others will find it useful in other ways - if you're an Outlook user it's certainly worth a try - you may well find it enhances your use of email in ways you never thought it needed enhancing!

Thursday
May012008

Sapien PowerShell Training Videos

I've just finished watching the samples of Sapien's new ScriptingAnswers.com "University" Class-On-Disc on Windows PowerShell Fundamentals. The HD video looks great and the content sample suggests that Don Jones' teaching would be well worth the price they're asking.

The spiel says '"University" titles are full-length self-paced training courses presented in a custom Adobe Flash interface. They include animations, hands-on activities, self-assessment quizzes, and other elements designed to duplicate the classroom experience as closely as possible - right on your desktop.'

I'm going to look to get the full PowerShell set (Fundamentals, Intermediate and Advanced) - currently available for $239 - a LOT cheaper than "the classroom experience"!

* This isn't a paid commercial ;-) I am in no way affiliated to Sapien Technologies although I did meet Don Jones once and found him to be a thoroughly decent guy. :-)

Monday
Apr282008

Tips for Windows Users

The FAQs on the departmental website at work is being replaced by a Tips section and around the same time the was a request for submissions for our new staff newsletter. This was my contribution...

 

Windows Live Photo Gallery

Microsoft provides a suite of free software under its Windows Live banner which provide enhancements to software included in Windows Vista, although the good news for Windows XP users is that you can take advantage of them too. The most significant piece of the suite is Windows Live Photo Gallery which is a simple to use, but very useful tool for importing photos from your camera, organising and editing and sharing them. The photo import tool is one of the best available, allowing you to easily group the photos on your camera into groups by the date taken, and you can easily alter the groupings so you get all the shots from last weeks holiday in one folder and the week before in a different one, or a different folder for every day or whatever you choose. Then you can rate and tag your photos, so you can easily show off just the 5-star snaps of your holiday in a slideshow, burn to cd, or upload them to Flickr. There's also an excellent panorama feature, which doesn't just work for creating wide landscapes - you can stitch photos horizontally and vertically to make a giant image and it doesn't matter if they're taken in portrait, landscape of at a jaunty angle - it'll work out how they all fit together. If you're not already using some other software to manage your digital photos on Windows, this is a really worthwhile download!

For more information about Windows Live Photo Gallery, got to http://get.live.com/photogallery/overview

Other applications in the Windows Live Suite that you may find useful are Windows Live Mail and Windows Live Writer. Windows Live Mail replaces Outlook Express on Windows XP or Windows Mail on Windows Vista and offers a number of enhancements. You can access multiple email accounts, including Hotmail and Gmail, you RSS news feeds and Windows Live Contacts (including your MSN/Live Messenger contacts) in one place. If you use Hotmail, this is easily the best way to access your mail and you can read and compose messages while you're offline. Window Live Writer is an editor for blog entries. If you have a blog, then you may want to give it a try since it's widely considered to be the best application of its kind and supports direct uploads to many of the most popular blogging platforms.

You can download Windows Live Photo Gallery and the rest of the Windows Live Suite from http://get.live.com

 

Take your files with you without a USB stick with Windows Live SkyDrive

There are many different alternatives for storing your files on the internet and many of them have similar features, so we don't have any reason for recommending Windows Live SkyDrive other than if you already use Hotmail or Windows Live Messenger (previously MSN Messenger), you've already for a SkyDrive account. With SkyDrive you can upload up to 5GB of files to your personal, shared or public folders, so you can keep some files private, share some with your friends and other with the whole internet. The only restriction is that the maximum single file you can upload is 50MB. Try it out at http://skydrive.live.com

 

Synchronise files between multiple computers and access them from anywhere with FolderShare

If you more than one PC, or even a PC and a Mac, perhaps a work computer and a home computer or a laptop, and you frequently find yourself moving files between them, then Windows Live FolderShare is a free service which may be of great help to you. Just install the client on your computers and then use the website to choose folders on those machines that you want to be synchronised and it'll just happen quietly in the background as long as both computers are on, for files up to 2GB. It works even if you have a firewall or if your computer is on a private network. A great additional feature is that if your computer is switched on with the FolderShare client running, you can logon to the FolderShare website to get access to any of your files on that computer from any web browser!

Find out more, and find the download links at http://www.foldershare.com/

 

Tab your way around

If you're doing work that involves a lot of typing, like filling in a web form, or even compiling an email in Outlook, then taking your hand away from the keyboard to click in the next box with the mouse can disrupt your flow. You can often get through a form a lot quicker by hitting the TAB key to move the cursor to the next box. Tabbed through too quickly? No problem, hold the SHIFT key and hit TAB to move backwards through the elements of the page or application.

A lot of the time you can avoid taking your hands off the keyboard at all. You can move through your open applications by holding the ALT key and hitting TAB, and yes, if you go past the application you want, you can keep holding ALT and SHIFT+TAB back to the previous application. On Windows Vista, you may be able to get a better view of the applications as you switch through them by using the Windows Logo key and TAB instead of ALT+TAB, but that is dependent on having that key and a graphically capable computer.

Learning the standard Windows keyboard shortcuts can be a real time-saver. Here's a quick overview of some more:
F1 : Show help
CTRL + A : Select all
CTRL + X : Cut
CTRL + C : Copy
CTRL + V : Paste
CTRL + Z : Undo
CTRL + Y : Redo
CTRL + S : Save
CTRL + ESC : Open Start menu (if you don't have a Windows logo key)
ALT + F4 : Close the current window
WIN + M : Minimize all windows

This one uses the mouse if you have one with a scroll-wheel:
CTRL + SCROLL : Zoom in/out (and also a quick way to change the view in Windows Explorer)

 

Where has the menu bar gone?

Newer versions of some Microsoft applications are missing the familiar menu bar (where you usually see menus such as File, Edit, View and Help). Prime examples of this are Windows Explorer in Windows Vista and the latest versions of Internet Explorer and Windows Media Player (7 and 11 respectively). Any amount of clicking or right-clicking around with the mouse won't find some of the options that are on these menus. The secret is to use the standard keyboard shortcut for accessing menu items - the left ALT key.

You can access the specific menus with their individual keyboard shortcut, e.g. ALT + F for the File menu or ALT + V for the View menu.

 

Use portable applications

Portable applications are most easily described as applications that can be run from a removable drive (like a USB flash drive), and take all their application data (settings) with them. There's a number of good reasons for using them:
1) You don't need to install them on a PC, so you don't need to have administrator rights.
2) You can take them with you, so you don't have to install an application and get it set up just how you like it multiple times.
3) Say you've written a web page and it looks fine in Internet Explorer, but you need to see how it looks in Firefox and Opera, you can use the portable versions without having to install them.
4) The more you install/uninstall software, the more likely you are to see decreased performance (from system registry growth and disk fragmentation).

There are portable versions of applications of practically every type. For example, all of these are available in versions which have been packaged to be portable:
Firefox (web browser with vast support for extensions)
VLC Media Player (media player which supports a large range of formats)
GIMP (image editor)
Audacity (audio file editor)
Foxit Reader (a great lightweight PDF file reader)
Skype (for making calls via the internet)
7-Zip (file compression utility)
FileZilla (FTP application)
uTorrent (bit torrent client)

A good place to start looking for portable applications which may be of use to you is http://www.portableapps.com and Wikipedia has a comprehensive list at http://en.wikipedia.org/wiki/List_of_Portable_Applications

Monday
Mar312008

Checking disk space on all servers in an OU

I was just running this bit of PowerShell and it occurred to me that other than in the demo script that I presented last December, I hadn't actually posted this on my blog.

To find out the free disk space on the servers in an OU containing SQL Servers:

([ADSI]LDAP://OU=SQL Servers,DC=yourdomain,DC=com).psbase.Children | ?{$_.ObjectCategory -like "*computer*"} | %{Write-Host $_.name; gwmi win32_LogicalDisk -comp $_.name -filter "DriveType=3" | ft DeviceID, @{Label="Gb Free(Approx.)";Expression={[int]($_.Freespace/1GB)}} -a}

To use this in your environment, just change the LDAP path to something relevant to your Active Directory.

This is very similar to what was presented by Don Jones in an article in TechNet Magazine (I just happened to write this a week or two before that article arrived in the January issue of the UK version of the mag). The main difference was that Don was looking at a list of servers from a text file, but since the SQL Servers that I was interested in were all in a particular OU, I could just look in there and not have to keep a list up to date in a file as servers are added/removed.

So what this does is look at the child objects in the SQL Servers OU (using psbase to expose .Children, which is obscured by PowerShell's ADSI implementation), and filters the objects to only pass computers - there's no need to check free disk space on users/groups/etc!

([ADSI]LDAP://OU=SQL Servers,DC=yourdomain,DC=com).psbase.Children | ?{$_.ObjectCategory -like "*computer*"}

Then, for each of these computers we do two things. Firstly we write the computer's name out, then we look at the logical disks with WMI. We need to filter on DriveType to only pick up local fixed disks. Here I learned from Don that I could use the filter on the Get-WmiObject cmdlet, because I originally had:

gwmi win32_LogicalDisk -comp $_.name | ?{$_.DriveType -eq 3}

Finally, I'm writing each of the drives out in a table, with the free space in Gb, since I'm not really interested in a more granular view than that. The output looks a bit like this:

SQL1

DeviceID Gb Free(Approx.)
-------- ----------------
C:                     15
D:                     33
F:                    125

SQL2

DeviceID Gb Free(Approx.)
-------- ----------------
C:                     12
D:                     15
F:                     37
G:                     59
H:                    100

SQL3

DeviceID Gb Free(Approx.)
-------- ----------------
C:                      1
F:                     21
G:                     33
H:                     66

Looks like I'd best have a look at the system disk on that 3rd server!

[update] When I first posted this, Brandon Shell left a comment suggesting using LDAP and WMI filters to make the code more efficient. He's right, but when I originally wrote the example, it was as an example of using the pipeline for PowerShell beginners. Still, in production, you might want to use his version:

$ds = new-Object System.DirectoryServices.DirectorySearcher([ADSI]"LDAP://OU=SQL Servers,DC=yourdomain,DC=com","(objectcategory=computer)",@('name'))
$ds.pagesize = 1000
$ds.findall() | %{Write-Host $_.properties.name; gwmi win32_LogicalDisk -comp $_.properties.name -filter "DriveType=3" | ft DeviceID, @{Label="Gb Free(Approx.)";Expression={[int]($_.Freespace/1GB)}} -auto}