Hello. I've been trying to figure this one out. I wrote the script in ISE then scheduled it to run but it did not run as expected. When i test run it in ISE it runs fine because the IF commands run no problem. At the command shell the IF is skipped. I may be missing something simple here. I appreciate any assistance.
Script: (The two Outputs are below) Note that Step 4 is inside the IF statement.
This script checks to see if exchange database replication has any issues on any of the databases. If there is an issue, the IncomingLogCopyingNetwork field is very long. If no issue, it is under 15 characters.
write-output "Step1, Populate databaselist" $databaseList = Get-MailboxDatabaseCopyStatus -server caprgmkmwembx1 -connectionstatus | select-object databasename,name, IncomingLogCopyingNetwork write-output "Step2, Set DBProblemCount to 0" $DBProblemCount = 0 foreach($databasename in $databaseList) { write-output "Step3, Inside ForEach" if ($databasename.IncomingLogCopyingNetwork.length -gt 25) { write-output "Step4, Inside IF" $DBProblemCount++ write-output $DBProblemCount } } if ($DBProblemCount -gt 1) { write-output "Step5, Send Email Message." #Send-MailMessage <Truncated for posting> #write-output $DBISSUELIST Send-MailMessage <Truncated for posting> } write-output "Step6, Send Email Message to State Script has run." Send-MailMessage <Truncated for posting>
PowerShell ISE Output:
Step1, Populate databaselist Step2, Set DBProblemCount to 0 Step3, Inside ForEach Step4, Inside IF 1 Step3, Inside ForEach Step4, Inside IF 2 Step3, Inside ForEach Step4, Inside IF 3 ...Truncated the incremental numbers. 46 Step3, Inside ForEach Step4, Inside IF 47 Step3, Inside ForEach Step4, Inside IF 48 Step3, Inside ForEach Step4, Inside IF 49 Step5, Send Email Message. Step6, Send Email Message to State Script has run.
PowerShell Shell Output:
Step1, Populate databaselist Step2, Set DBProblemCount to 0 Step3, Inside ForEach Step3, Inside ForEach Step3, Inside ForEach
...Truncated the incremental.
Step3, Inside ForEach Step3, Inside ForEach Step3, Inside ForEach Step3, Inside ForEach Step3, Inside ForEach Step6, Send Email Message to State Script has run.
~~~ Mark Orser Pernod Ricard Americas