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
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"
}
}
error-disconnecting-mailbox.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thx for the quick reply
ASKER