VBScript에서 PowerShell 명령을 실행하고 있습니다.VBScript의 PowerShell에서 오류 메시지를 다시 얻는 방법
다음은 내가 Enable-Mailbox
명령이 실패 할 때 그래서 다시 오류 메시지가 오지 않는
'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)
를 실행하고 VBScript를합니다. 해당 메시지를 어떻게 캡처하여 사용자에게 다시 보내야합니까?
try/catch Enable-Mailbox. 제대로 작동하지 않을 때 0이 아닌 종료 코드를 반환합니다. 오류 코드의 의미를 문서화하거나 기록하십시오. % LASTEXITCODE %를 검사하십시오. 아니면 PowerShell로 모든 것을 옮기고 래퍼를 제거하십시오 :) –