Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to analyze ERRORLEVEL in the script

Reply
 
Old 03-13-2008   #1 (permalink)
Eugene Borisov


 
 

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]


 
 

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]


 
 

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


 
 

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


 
 

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]


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Analyze Disk Fragmentation Vista performance & maintenance
Help analyze my Netmon capture? Network & Sharing
How to set errorlevel env variable properly from a simple batch file: Answered Vista General
ErrorLevel PowerShell
checking errorlevel? PowerShell


Vista Forums 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 Ltd

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