I am running a PowerShell command like this in a VBScript.
Below is the VBScript I am running
'This Script is used for creating Mailboxes for Active Directory Users.
'This script triggers a Power Shell Script which creates the mailbox for the
'ActiveDirectory User.
'
Set args = WScript.Arguments
'Argument 0 contains the identity User Name
WScript.Echo args.Item(0)
'Argument 1 contains the Mail Store Alias Name
WScript.Echo args.Item(1)
'Argument 2 contains the Mail Database
WScript.Echo args.Item(2)
'Argument 3 contains the Report Log Path
WScript.Echo args.Item(3)
On Error Resume Next
Dim shell
Set shell = CreateObject("WScript.Shell")
'Firing the PowerShell command from VBScript
shell.Run "PowerShell.exe -PSConsoleFile ""E:\Program Files\Microsoft\Exchange Server\Bin\exshell.psc1"" -NoExit ""&{""Enable-Mailbox -Identity '"&Replace(args.Item(0),"'", "''")&"' -Alias '"&args.Item(1)&"' -Database '"&args.Item(2)&"';""exit 0""} ",,20
If Err.Number <> 0 Then
WScript.Echo("Error Occurred in CreateMailBoxExchange script" & Err.Description)
WScript.Quit(2)
End If
WScript.Quit(3)
So when Enable-Mailbox command fails it does not come back with the error message. How should I capture that message and send it back to the user?