Link to home
Start Free TrialLog in
Avatar of bndit
bndit

asked on

Powershell script to disconnect Exchange 2003 mailboxes not working

I'm using a script that I found at PowerGui.org website but I'm running into problems. I tested the script in a test environment with Exchange 2003 installed on the DC, and the script worked just fine. However, when I run the script from my Win7 machine in my production network to delete mailboxes on my Exchange 2003, I run into problems saying that there was a problem with the "deletemailbox" method. Any idea what I'm missing? I'm including the script and a snapshot of the error message.

http://www.powergui.org/thread.jspa?messageID=33010
$strDCName = "SERVER1"

Import-Csv "c:\myfile.csv" | `
ForEach {
	#$dn = (Get-QADUser -identity $Username | Select-Object dn).dn
	$today = $(Get-Date).ToShortDateString()
	$name = $_.DisplayName
	$dn = (Get-QADUser -Identity $_.NTAccountName | Select-Object DN).dn
	$homeMDB = (Get-QADUser -Identity $_.NTAccountName -IncludedProperties homeMDB | Select-Object homeMDB).homeMDB
	
	$user = [adsi]("LDAP://$strDCName/$dn")

	if ($homeMDB -eq $null) {
		Write-Host "User does not have a mailbox"
		}

	else {
		$user.DeleteMailbox()
		$user.Description = "Disconnected mailbox via script, $today"
		$user.SetInfo()
		Write-Host "Deleted mailbox for $name"
		}
}

Open in new window

error-disconnecting-mailbox.png
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bndit
bndit

ASKER

As always, thanks Chris. I'll award you the points as you answered my question...However, what would you suggest to accomplish the same goal without having to install the Exchange 2003 tools? Installing the Exchange 2003 is a bit messy on Windows 7, and I'd like to disconnect mailboxes without having to install them, if possible.
Avatar of bndit

ASKER

Thx for the quick reply