Exit code for powershell commands
Hi I have a powershell script "MountDB.ps1" which will mount the database. The ps1 file contains the following code $HostName = [System.Net.Dns]::GetHostName() Add-PSSnapin -name Microsoft.Exchange.Management.PowerShell.Admin Get-MailboxDatabase -Server $HostName | Mount-Database -Force echo $LASTEXITCODE Here I want to get the exit code for the cmdlet "Get-MailboxDatabase" . I ran this script using powershell.exe , "LASTEXITCODE" returns nothing. But if I run the same script using Exchange Management shell it returns the exitcode as 0. Can anyone explain this ? I want to run the script using powershell.exe Thanks Inmar Can anyone te
June 10th, 2010 4:01pm

Hi, This problem also happens in my exchange server. When using powershell, the $LASTEXITCODE cannot work for exchange scripts. I think it is by design. To check if the database is mounted, you can use the following script: $ifMounted= (Get-MailboxDatabase "Mailbox Database" -status).Mounted echo $ifMounted
Free Windows Admin Tool Kit Click here and download it now
June 11th, 2010 11:00am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics