header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Capturing POSH errors in a DOS command file
Last Post 10 Aug 2010 08:35 AM by jamiet. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
jamietUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Aug 2010 08:18 AM
    Hi,
    Dumb newbie question here (again).

    I have a POSH script that I am calling from a .cmd command file. It seems that any errors that occur in my POSH script don't get returned to my .cmd file. Can anyone explain how to do this please?

    Here are my scripts. First, script.ps1:
    cd NonExistentFolder

    and runPS.cmd:
    powershell.exe c:\temp\POSHTest\script.ps1
    echo %ERRORLEVEL%

    When I execute "runPS.cmd from the command-line I get:
    0

    Evidently the error that the Powershell script would have produced is not getting returned to the DOS cmd file. Anyone know why not?

    thanks in advance
    Jamie
    jamietUser is Offline
    New Member
    New Member
    Posts:12
    Avatar

    --
    10 Aug 2010 08:35 AM
    OK, I got an answer via Twitter that seems to work:

    cd NonExistentFolder
    if (-not $?) {exit 10}
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer