Help with PS Script to correct PF corruption
we are running Exchange 2007 / 2003 mixed in a windows 2003 Native AD. We did a reinstall -in disaster recovery of one of our Exchange 2003 servers -that hosts a PF structure. We now have a problem that requires us to Mail Disable then mail enable
all of the previously mail enabled folders. We are trying to use modified (portion of a) script that was initially used to create the structure. We have a text file that contains the Office numbers that exist in the PF structure. It's
failing at the Folder for each command (line9). I've attached what we are trying to use and the failure statement. Any assistance is greatly appreciated;
$salesoffices = gc "c:\shell\reports\SalesOffices.txt"
foreach ($office in $salesoffices)
# Mail Enable the Request folders
# Write-Host "Pausing to allow Active Directory recognition of new folders"
# Sleep 25
Write-Host "Mail DisEnable the Request folders"
$mailfolders = Get-PublicFolder "\Sales Force Mail\$office" -Recurse |where {$_.name -match "Requests"}
foreach($folder in $mailfolders){Disable-MailPublicFolder $folder -HiddenFromAddressListsEnabled $true}
Write-Host "Mail Disable the AntiSpam folder"
Get-PublicFolder "\Sales Force Mail\$office\$office$Archive\$office$AntiSpam" |Disable-MailPublicFolder -HiddenFromAddressListsEnabled $true
# Write-Host "Mail Enable the Request folders"
# $mailfolders = Get-PublicFolder "\Sales Force Mail\$office" -Recurse |where {$_.name -match "Requests"}
# foreach($folder in $mailfolders){Enable-MailPublicFolder $folder -HiddenFromAddressListsEnabled $true}
# Write-Host "Mail Enable the AntiSpam folder"
# Get-PublicFolder "\Sales Force Mail\$office\$office$Archive\$office$AntiSpam" |Enable-MailPublicFolder -HiddenFromAddressListsEnabled $true
Missing statement body in foreach loop.
At c:\shell\PF-MAIL-Dis-Re-EnAble.ps1:9 char:1
+ <<<< Write-Host "Mail DisEnable the Request folders"
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingForeachStatement
September 14th, 2011 3:56pm
You're missing the curly brackets. This is what the error is telling you. I didn't check the rest; you'll have to run it and get the next error.
$salesoffices = gc "c:\shell\reports\SalesOffices.txt"
foreach ($office in $salesoffices)
{
# Mail Enable the Request folders
# Write-Host "Pausing to allow Active Directory recognition of new folders"
# Sleep 25
Write-Host "Mail DisEnable the Request folders"
$mailfolders = Get-PublicFolder "\Sales Force Mail\$office" -Recurse |where {$_.name -match "Requests"}
foreach($folder in $mailfolders){Disable-MailPublicFolder $folder -HiddenFromAddressListsEnabled $true}
Write-Host "Mail Disable the AntiSpam folder"
Get-PublicFolder "\Sales Force Mail\$office\$office$Archive\$office$AntiSpam" |Disable-MailPublicFolder -HiddenFromAddressListsEnabled $true
# Write-Host "Mail Enable the Request folders"
# $mailfolders = Get-PublicFolder "\Sales Force Mail\$office" -Recurse |where {$_.name -match "Requests"}
# foreach($folder in $mailfolders){Enable-MailPublicFolder $folder -HiddenFromAddressListsEnabled $true}
# Write-Host "Mail Enable the AntiSpam folder"
# Get-PublicFolder "\Sales Force Mail\$office\$office$Archive\$office$AntiSpam" |Enable-MailPublicFolder -HiddenFromAddressListsEnabled $true
}
Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
September 14th, 2011 8:20pm
thank you, I added them and got a diferent error -I confirmed there is a replica on an exchange 2007 server;
Cannot find an available public folder database. Please make sure that there is
a public folder database on an Exchange 2007 mailbox server, and then ensure t
hat the public folder database is mounted.
At c:\shell\PF-MAIL-Dis-Re-EnAble.ps1:12 char:16
+
$mailfolders = <<<< Get-PublicFolder "\Sales Force Mail\$office" -Recurse |
where {$_.name -match "Requests"}
+ CategoryInfo
: InvalidOperation: (:) [], InvalidOperationExcept
ion
+ FullyQualifiedErrorId : B4E13B83
Disable-MailPublicFolder : Cannot bind argument to parameter 'Identity' because
it is null.
At c:\shell\PF-MAIL-Dis-Re-EnAble.ps1:13 char:59
+
foreach($folder in $mailfolders){Disable-MailPublicFolder <<<<
$folder }
+ CategoryInfo
: InvalidData: (:) [Disable-MailPublicFolder], Par
ameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
icrosoft.Exchange.Management.MapiTasks.DisableMailPublicFolder
September 15th, 2011 9:25am
In general, you don't want to construct strings in the command. Instead of:
$mailfolders = Get-PublicFolder "\Sales Force Mail\$office" -Recurse |where {$_.name -match "Requests"}
do this:
$Folder = "\Sales Force Mail\" + $office
$mailfolders = Get-PublicFolder $Folder -Recurse | where {$_.name -match "Requests"}
I'm not sure that'll fix your problem, though. To solve such problems, start small and work out. For example, first in a EMS window, start with:
$Folder = "\Sales Force Mail\" + $office
Get-PublicFolder $Folder -Recurse
and verify that your Get works.
Also, are you trying to match the exact string "Requests" or did you intend to have a wildcard in there?
Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
September 15th, 2011 9:45am
I got the script to work with your assistance. Thank You
September 21st, 2011 8:36am