Here is a Powershell script you can use to quickly determine the total amount of space taken up by all of your Exchange database files (edb files) on an Exchange server. I’d like to note that this may not necessarily be a 100% accurate representation but is a great way to get a ballpark number without having to add the numbers up yourself, manually.
I noticed that I had no way to calculate the total amount of space being used by my Exchange databases the other day. And even after scouring through teh Googles I was unable to find what I was looking for quickly so I wrote this script up quick to fix that problem. Just copy the previous bit of code into a ps1 file with notepad and execute the script from your EMS. It is a super simple way to iterate through all the databases, save their sizes to a variable and then spit that variable out when it is complete.
Recently I ran into an issue with a Lync environment (2010) where Lync conversations were not being saved to the “Conversation History” folder in Outlook (2010). Luckily there is a quick way to fix this issue, through Exchange. From the reading that I have done it seems like the most common reason this occurs is when a user in your Exchange environment reaches or surpasses 1,000 combined folders and sub folders in their mailbox. The easiest way to check if a user has reached this threshold is to use the Exchange Management Shell to quickly take a look at their total combined mailbox folders using the following command.
(Get-MailboxFolderStatistics “user”).Count
Easy enough, often times this is enough to determine the cause. But I have taken this command one step further and wrapped it into a little script that will go through your Exchange environment and record all users that have reached this threshold and place their display name as well as the number of folders/subfolders into a csv file for an easier to reference. Here is the logic of the script.
That logic right there is very basic but will iterate over all mailboxes in the Exchange environment, grab those with over 1,000 folders/sub folders, place them into an array and output the array. This will take a while depending on the size of your environment, so feel free to let it run in the background. It is not a super intensive process, it just takes forever. To get this into a CSV file use the following Powershell command, I have this script name Get-Folders.ps1 in this example.
.\Get-Folders.ps1 | Export-CSV users.csv
That should be it. Not everybody will need this obviously but I found that it came in handy.
I had a strange issue come up recently where mail administrators were unable to allow Exchange to pick which mailbox database to place users into (I’m not quite sure what this feature is called so we’re going with automatic load balancing) when they were creating new user mailbox profiles. This feature essentially picks a database at random as a way to balance and spread out mailboxes among databases. Makes, sense to me. Anyway, I’m thinking we may have installed an update that changed the behavior because this feature had apparently been working up until we installed Rollup 5-v2. So it appears that this update had broken this automatic mailbox load balancing functionality, although I’m not 100% sure. I just wanted to mention it in case some of you are looking for clues as to why this is happening.
So here is what the error looks like when allowing Exchange to choose which database to use when a new user is initially created.
Error: Load balancing failed to find a valid mailbox database.
Hmm, okay. That is weird. You can check to see if the database is set to be allowed with this command.
get-mailboxdatabase | ft name,isexcludedfromprovisioning
In my case, all of my mailbox databases came back true, so they are unable to be used for automatically selecting a database when the user created. To fix this, go ahead and run the following.
Now go ahead and run the first command again and you should see that all the mailboxes are now marked as false, meaning they are now included in the provisioning process.
Now you should be able to go through and create without selecing a specific mailbox. My best guess is that the update must have set this flag to exclude these databases from provisioning but is weird and is worth mentioning because it happened to cause some seemingly unexplained issues for us.
Wow it feels like it’s been forever since I have posted. I have been crazy busy with work stuff and am just now getting caught up with everything and have enough room to poke my head above the water and breath again finally. We had a massive overhaul of our data center in mid February (among other things) and I am finally getting all the loose ends tied up from that project, including our brand-spanking new test environment which I am super excited about and which I will post about in the not so distant future.
Here is proof of some of our efforts just in case you don’t believe me 🙂
Anyway, getting back on track, I just discovered a slick way in Powershell to mimic the functionality of tail and tail -f in the Linux world. If you have ever used tail then you know it is a great tool for monitoring log files or quickly looking at the end of a piece of code for example.
With the trick I’m about to show you, the same can essentially be done in Windows. However, there are a few caveats. For one, the syntax is a little bit different (if you want to change this just set up an alias). The Powershell equivalent relies on the Get-Content cmdlet with the -Tail and -Wait flags to accomplish this task.
So in the following example I have instructed Powershell to look at the last 30 lines of the uploadpic.ps1 file and using the -Wait flag it will be updated as the file gets appended to.
Get-Content -path .\uploadpic.ps1 -Tail 30 -Wait
If you don’t care about viewing the file live then you can remove the -Wait flag and Powershell will simply grab the last N number of lines where N is 30 in our example. 30 seems like a good enough number in our example and can obviously be changed depending on your needs. Easy enough for what I need it for.
Get-Content -path .\uploadpic.ps1 -Tail 30
As I mentioned, I will be going into a little more detail about some of the things I learned from our data center rebuild that I feel were some great lessons and good things to know/be aware of. Standby for new contents as I get back to writing more blog posts and getting back up to speed on the writing side of things.
For the longest time I have not been a fan of embracing the shell in the Windows world, but more and more I find that Powershell is able to do the things that I need. I suppose my seething hatred was in part due to my negative bias towards Windows and the lack of useful tools from the command line in Windows. Increasingly lately, I have been changing the way I think about and utilize the command line in Windows with Powershell. And to be honest, I’m really beginning to fall in love with Powershell the more I get work with it and the more I get to see how to apply it in Windows based environments. The good news is that Microsoft has put a lot of effort into this and are adding improvements and features all the time. It still has a long way to go, but I can already see this as an alternative to GUI based administration in the Windows world and finally begin to feel like I can see the promise land on the horizon. Using Powershell has been somewhat of a paradigm shift (in my opinion anyways) to how to do Windows administration recently and I feel like it will only get stronger and more common in the years to come. So in this post I will try to show you some of the flexibility as well as some of the power that Powershell has to offer with some great tools from the community.
To highlight what I am talking about, let’s talk about grep, a well known and loved tool in the *nix universe. I love grep. For the longest time, I hadn’t known of a way to grep in the Windows world until just recently with a wonderful third party Powershell module called Find-String. There are a few commands that you need to get this working. To start, we need to get a module installed that is basically used for package management. This tool is called PsGet. Installation is super simple, just run the following from a Powershell prompt, and ensure that your execution policy is set at least at remotesigned (Set-ExecutionPolicy RemoteSigned if you don’t have this turned on).
This should go out, download and install PsGet for you. Once all that has completed you should be able to install Powershell modules that are contained in the PsGet repository. With this installed we can just reach out to the PsGet repo and install our module.
Install-Module Find-String
Easy, simple, and clean. That is the best part, there isn’t a ton of leg work to get this stuff working correctly and is why I’m enjoying Powershell so much these days. Now we have a very functional grep clone! Usage is quite a bit similar to grep, fore help you can do a Get-Help Find-String or look at the link I posted earlier to the author’s github page. If you want to look for a word or substring in a file just use something like this:
Find-String word example.txt
This will output all occurrences of the word you are looking for in the file example.txt. Here is a screen shot to show you.
What other cool Powershell stuff are you doing? I would love to hear about other cool uses that can be beneficial in every day use.