Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
General PowerShell
Capturing POSH errors in a DOS command file
Last Post 10 Aug 2010 08:35 AM by
jamiet
. 1 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
jamiet
New Member
Posts:12
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
jamiet
New Member
Posts:12
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.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2