Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

How to analyze ERRORLEVEL in the script

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-13-2008   #1 (permalink)
Eugene Borisov
Guest


 

How to analyze ERRORLEVEL in the script

Hello,

I am building my first script in PowerShell. I included external application
(WinZip) in it and all works fine. Now, I want to analyze the result of
Winzip by looking into ERRORLEVEL like I was able to do in CMD shell in old
times, but can't figure that out. If anyone has an idea how to expose
ERRORLEVEL, please share.

Thank you
Eugene



My System SpecsSystem Spec
Old 03-13-2008   #2 (permalink)
Brandon Shell [MVP]
Guest


 

Re: How to analyze ERRORLEVEL in the script

Take a look at this
http://bsonposh.com/modules/wordpress/?cat=11

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

EB> Hello,
EB>
EB> I am building my first script in PowerShell. I included external
EB> application (WinZip) in it and all works fine. Now, I want to
EB> analyze the result of Winzip by looking into ERRORLEVEL like I was
EB> able to do in CMD shell in old times, but can't figure that out. If
EB> anyone has an idea how to expose ERRORLEVEL, please share.
EB>
EB> Thank you
EB> Eugene


My System SpecsSystem Spec
Old 03-13-2008   #3 (permalink)
Keith Hill [MVP]
Guest


 

Re: How to analyze ERRORLEVEL in the script

"Eugene Borisov" <yevgeniy@xxxxxx> wrote in message
news:uC8ywaUhIHA.2540@xxxxxx
Quote:

> Hello,
>
> I am building my first script in PowerShell. I included external
> application (WinZip) in it and all works fine. Now, I want to analyze the
> result of Winzip by looking into ERRORLEVEL like I was able to do in CMD
> shell in old times, but can't figure that out. If anyone has an idea how
> to expose ERRORLEVEL, please share.
These two functions are in my standard library of PS funcs:

function Get-CallStack {
trap { continue }
1..100 | foreach {
$var = Get-Variable -scope $_ MyInvocation
$var.Value.PositionMessage -replace "`n"
}
}

#--------------------------------------------------------------------
# Helper function to deal with legacy exe exit codes
#--------------------------------------------------------------------
function CheckLastExitCode {
param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null)

if ($SuccessCodes -notcontains $LastExitCode) {
if ($CleanupScript) {
"Executing cleanup script: $CleanupScript"
&$CleanupScript
}
$OFS = $NL = [System.Environment]::NewLine
throw "EXE RETURNED EXIT CODE ${LastExitCode}${NL}$(Get-CallStack)"
}
}

Use like so:

& $WinZipPath <params>
CheckLastExitCode

If use TFS command line:

& $TfPath get $DevRoot /r
CheckLastExitCode @(0,1)

Here I specify that both 0 and 1 exit codes are considered success.

--
Keith

My System SpecsSystem Spec
Old 03-14-2008   #4 (permalink)
Eugene Borisov
Guest


 

Re: How to analyze ERRORLEVEL in the script

Brandon and Keith,

This is much more that I expected - thank you very much. Your both answers
completeley cover the topic. Even CheckLastExitCode is a great function and
I will keep it in mind, simple $LASTEXITCODE will do it for me for now.

Thanks again for helping me out. Cheers.

"Eugene Borisov" <yevgeniy@xxxxxx> wrote in message
news:uC8ywaUhIHA.2540@xxxxxx
Quote:

> Hello,
>
> I am building my first script in PowerShell. I included external
> application (WinZip) in it and all works fine. Now, I want to analyze the
> result of Winzip by looking into ERRORLEVEL like I was able to do in CMD
> shell in old times, but can't figure that out. If anyone has an idea how
> to expose ERRORLEVEL, please share.
>
> Thank you
> Eugene
>

My System SpecsSystem Spec
Old 03-14-2008   #5 (permalink)
Flowering Weeds
Guest


 

Re: How to analyze ERRORLEVEL in the script


"Eugene Borisov"
Quote:

>
> I am building my first script in PowerShell. I
> included external application (WinZip) in it
> and all works fine. Now, I want to analyze the
> result of Winzip by looking into ERRORLEVEL
> like I was able to do in CMD shell in old times,
> but can't figure that out. If anyone has an idea
> how to expose ERRORLEVEL, please share.
>
Perhaps an example using the free
IIS's Microsoft's data parser,
Log Parser 2.2 (with a built-in
Microsoft ChartSpace chart maker).

Notice: IIS does not need to be running
or installed in order to use Log Parser
for either data parsing or chart making.

PS> LogParser.exe "SELECT"
Error: Syntax Error: <field-expr>:
cannot find a valid <field-expr>:''
PS>

Mmmm did Microsoft's data parser fail?

PS> $LastExitCode
1615
PS>

Mmmm what does that error number
mean?

Well using Microsoft's Common Error
Lookup Tool.

PS> err.exe 1615
# for decimal 1615 / hex 0x64f :
ecInvLogonHrs ec.h
ERROR_BAD_QUERY_SYNTAX winerror.h
# SQL query syntax invalid or unsupported.
# 2 matches found for "1615"
PS>

Mmmm did Microsoft's Common Error
Lookup Tool (err.exe) run okay?

PS> $LastExitCode
0
PS>

Search the Internet for usage of:

Microsoft's Log Parser
(from the IIS group)

and

Microsoft's ChartSpace Charting
as used within Log Parser, Excel
or even stand alone scripting usage
(from the Office group)

and

Microsoft's Common Error Lookup Tool
(from the Exchange group)

Just three other PowerShell tools ways!


My System SpecsSystem Spec
Old 03-14-2008   #6 (permalink)
Brandon Shell [MVP]
Guest


 

Re: How to analyze ERRORLEVEL in the script

Dude.. I have to know. Did you write this product? Your passion is amazing!

"Flowering Weeds" <floweringnoweedsno@xxxxxx> wrote in message
news:%23TQZ3OfhIHA.5260@xxxxxx
Quote:

>
> "Eugene Borisov"
>
Quote:

>>
>> I am building my first script in PowerShell. I
>> included external application (WinZip) in it
>> and all works fine. Now, I want to analyze the
>> result of Winzip by looking into ERRORLEVEL
>> like I was able to do in CMD shell in old times,
>> but can't figure that out. If anyone has an idea
>> how to expose ERRORLEVEL, please share.
>>
>
> Perhaps an example using the free
> IIS's Microsoft's data parser,
> Log Parser 2.2 (with a built-in
> Microsoft ChartSpace chart maker).
>
> Notice: IIS does not need to be running
> or installed in order to use Log Parser
> for either data parsing or chart making.
>
> PS> LogParser.exe "SELECT"
> Error: Syntax Error: <field-expr>:
> cannot find a valid <field-expr>:''
> PS>
>
> Mmmm did Microsoft's data parser fail?
>
> PS> $LastExitCode
> 1615
> PS>
>
> Mmmm what does that error number
> mean?
>
> Well using Microsoft's Common Error
> Lookup Tool.
>
> PS> err.exe 1615
> # for decimal 1615 / hex 0x64f :
> ecInvLogonHrs ec.h
> ERROR_BAD_QUERY_SYNTAX winerror.h
> # SQL query syntax invalid or unsupported.
> # 2 matches found for "1615"
> PS>
>
> Mmmm did Microsoft's Common Error
> Lookup Tool (err.exe) run okay?
>
> PS> $LastExitCode
> 0
> PS>
>
> Search the Internet for usage of:
>
> Microsoft's Log Parser
> (from the IIS group)
>
> and
>
> Microsoft's ChartSpace Charting
> as used within Log Parser, Excel
> or even stand alone scripting usage
> (from the Office group)
>
> and
>
> Microsoft's Common Error Lookup Tool
> (from the Exchange group)
>
> Just three other PowerShell tools ways!
>
>
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help analyze this blue screen! Hank Vista General 14 07-04-2008 02:49 PM
Analyze Disk Fragmentation Benzmum Vista performance & maintenance 23 09-30-2007 07:09 PM
ErrorLevel Dan PowerShell 5 08-06-2007 01:40 AM
howto analyze fix setup? Egbert Nierop \(MVP for IIS\) Vista installation & setup 5 01-11-2007 10:21 AM
checking errorlevel? =?Utf-8?B?TWljaGFlbCBLZWxsZXk=?= PowerShell 1 09-14-2006 07:29 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51