All posts by bsdman

Currently working as an IT Manager. Worked for an OIT company as a Network Engineer in 2011. Worked for a Medical IT company as the Network Administrator 2009-2011. Worked as the Senior Systems Administrator at a computer reseller from 2005-2009. Worked as a Computer Consultant for several small companies from 2007-2009. Worked as a Computer Technician at a computer reseller from 2002-2004.

Exchange 2007 Mailbox Statistics

If only Microsoft would realize that it’s pretty easy to add a single column known as “size of mailbox” when searching through the GUI exchange management tool. Instead, we have to open up the Command prompt tool. Big deal.

Here’s the quick and easy way to list the name of the mailbox, size of said mailbox, and number of emails:
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount

And apparently you can get it to email you if you write a script as follows:
###Send mailbox statistics script
###First, the administrator must change the mail message values in this section
$FromAddress = "MailboxReport@ngh.net"
$ToAddress = "administrator@ngh.net"
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "e2k7.ngh.net"
###Now get the stats and store in a text file
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}}, ItemCount > mailboxes.txt
###Create the mail message and add the statistics text file as an attachment
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress,
$MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment("./mailboxes.txt")
$SMTPMessage.Attachments.Add($Attachment)
###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

But I couldn’t get it to actually attach the txt document.

EDIT!!!

11.11.2008

I got it to work – the problem was with a couple issues we had.

1.) In the Windows PowerShell, you must Set-ExecutionPolicy Unrestricted
2.) I wrote a bat file to open this once a week:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -command ". 'C:\sendstats.ps1'"
3.) I wrote a ps1 file to run the actual commands (see above for the code)
4.) If you get an error, see if the following command helps:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
5.) MAKE SURE the get-mailboxstatistics is all on one single line – I can’t tell you how much word-wrap in notepad screwed me out of 20 minutes of time.

***EDIT 05.23.2011***
So Exchange 2010 screwed me a little bit on this – it requires another flag:
Get-MailboxStatistics -server SERVERNAME | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount

You can use -Identity MAILBOXORUSERNAME, -Database DATABASEHERE, or -Server SERVERNAMEHERE. I chose server as it’s exactly what I needed.

Exchange 2007 Remove Disconnected Mailboxes

If you delete a user on Exchange 2007, it will delete the user in Active Directory. It will not, however, delete the mailbox that was associated with the user. This mailbox will then move onto bigger and better things – namely just taking up storage space on your Exchange server.

Quick and easy way:
On your Exchange server, open up the Exchange Management Shell
Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid – This will show all the disconnected mailboxes AND their associated MailboxGuid (which is needed to delete the boxes)
Remove-Mailbox -Database [Database-Name] -StoreMailboxIdentity [MailboxGuid] – This will delete a single line item.

EDIT 11.13.2008:
You can run the Get-MailboxDatabase command to find out the name of the database and what server it resides on. The final delete command will be something like the following:
Remove-Mailbox -Database "servername\mailbox database" -StoreMailboxIdentity 2ae3c6f1-848e-4892-923c-614f9b3838f7
Then it will ask if you want to really remove the GUID from the database.

Show and Hide Hidden Formatting Word

Sometimes people complain that they are seeing the hidden formatting characters on emails they’re trying to send. And then they are worried that their customers will also see said formatting marks. While I can explain that the customer will only see the text and not the marks, it’s actually much easier to just solve the problem.

Word 2003 had it nice and easy – just click on the standard toolbar Paragraph Mark. But with 2007, everything is hidden or moved. Don’t get me wrong – I like 2007 so far, but finding various tasks that used to be easy to explain are now hidden away somewheres.

And finding the key combination to reset this is difficult because NO ONE WRITES ABOUT IT.

So here’s the key combination:
Alt + Shift + 8. Just press the magic keys somewhere in your word document (or in the body of an email) and like magic (sense a theme going on?) they show/hide at your command.

Set Static IP Remotely

Because I rule, I decided to be able to change people’s IP addresses remotely. This usually requires a Domain Administrator account (which I have/am). Here’s the code for my remote script:

intValue = InputBox("Please enter a computer name:")
intValue2 = InputBox("Please enter an IP address:")
strComputer = intValue
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strGateway = Array("10.1.3.1")
strIPAddress = Array(intValue2)
strSubnetMask = Array("255.255.255.0")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
arrDNSServers = Array("10.1.1.124", "10.1.1.241")
objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next

Basically this script asks for the current computername (or IP address) and then the future IP address. I hardcoded the netmask and the DNS server IPs (as well as the default gateway) already because those never change for my needs. Obviously you should change the above numbers to what you require.

But then, after installing a new version of windows, I realized I was getting errors. The exact error is VBScript runtime error: 800A0046 Permission Denied: ‘GetObject’. Somehow I was being denied the ability to impersonate the local administrator using my script. I thought maybe it was a “new system” issue, so I tried it on an older machine (from my machine though) and it still failed. That narrowed it down to an issue on my machine.

It all boils down to DCOM not being enabled on the computer. DCOM, if disabled, makes for a more secure system (I’m basing that on all the trojans and viruses written to overflow the DCOM stack and take over systems – as well as all the patches written specifically to fix DCOM errors). However, DCOM is required by impersonation scripts like the one above.

Fix:
Open Control panels
Open Administrative Tools
Open Component Services
Navigate to Console Root >> Component Services >> Computers
Right Click My Computer and select Properties
Click on the Default Properties Tab
Click on Enable Distributed COM on this computer

Some people will require a reboot, but my script works just fine after clicking OK.

[EDIT]

It has come to my attention that a lot of people would like to do this remotely. And by a “lot of people” I mainly mean me.
Here’s how:
Open up regedit (start >> run >> regedit)
Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\OLE
You will see a REG_SZ key with the name EnableDCOM
Change the value of the key to Y for yes, or N for no. Then reboot the remote system.

Vista Shutdown Button

One of the biggest problems with Vista I found was the “shutdown button” would always put the computer into hibernate mode. Who would ever use hibernate mode anyway? I mean, come on, it’d be better to use sleep mode at that point. Jerks!

So anyway, here’s the quick fix:
Go into Power Options control panel
Under advanced settings find the “Power buttons and lid” option
Then look for “Start menu power button”
Now you’ll have different options to choose from. I personally picked Shut down.

Mapi32.dll Is Corrupt Or The Wrong Version

The error of “Cannot start Microsoft Office Outlook. Mapi32.dll is corrupt or the wrong version. This could have been caused by installing other messaging software. Please re-install office.” is a painful reminder that not all software pieces work well together. Quick fix:

1.) Close outlook
2.) Navigate to C:\Program Files\Common Files\System\MSMAPI\1033
3.) Rename MSMAPI32.DLL to MSMAPI32.DLL.OLD
4.) Reopen outlook – outlook should then “fix” this dll file

Daylight Savings Time Windows 2000

I know, I know… why would anyone still be using Windows 2000? You’d be surprised at that answer. At my place of business, all of our servers are Windows 2003 or Linux based with the exception of one key group: the Cisco Call Managers group.

DST changed a year or so ago, and all major operating systems were already patched by then. Unfortunately, Microsoft has labeled Windows 2000 under its EOL (end of life) software suite. Unless there’s a major security patch, all hot fixes are only for paying customers.

But Microsoft has a program called “TZEDIT.EXE” (found here) that allows you to manually edit the Time Zone configuration files.

1.) download the TZEDIT.EXE application
2.) Run the application, it will extract to C:\program files\tzedit
3.) Run the application in the \tzedit folder
4.) Click on your time zone and then hit the Edit button
5.) Starts 2nd Sunday of March @ 2 AM, Ends 1st Sunday of November @ 2 AM
6.) Now, double click on your time clock/calendar
7.) Select a different time zone and hit apply
8.) Select your edited time zone and hit apply
9.) All set!