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

error checking

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-10-2007   #1 (permalink)
IT Staff
Guest


 

error checking

in vbscript, i usually have this :

If Wscript.Arguments.Count <> 2 Then
Wscript.Echo "Syntax Error. Correct syntax is:"
Wscript.Echo
Wscript.Echo "cscript kb.vbs <drive:filename.ext> <kbxxxxx>"
Wscript.Quit
End If

Now what is the equivlent in powershell especially on the argument part ?

Is the a wscript.quit equivalent ?

As for the rest, i assume write-host can be used for the wscript.echo parts.







My System SpecsSystem Spec
Old 01-10-2007   #2 (permalink)
Brandon Shell
Guest


 

Re: error checking

I have notice that alot of your questions are about VBscript to PowerShell
Translation.
Think link maybe helpful:
http://www.microsoft.com/technet/scr...t/default.mspx

Now.. about your question:

if(!$args){
Write-Host "Syntax Error. Correct syntax is: ..."
Break
}


"IT Staff" <jkklim@hotmail.com> wrote in message
news:enx0qtRNHHA.2140@TK2MSFTNGP03.phx.gbl...
> in vbscript, i usually have this :
>
> If Wscript.Arguments.Count <> 2 Then
> Wscript.Echo "Syntax Error. Correct syntax is:"
> Wscript.Echo
> Wscript.Echo "cscript kb.vbs <drive:filename.ext> <kbxxxxx>"
> Wscript.Quit
> End If
>
> Now what is the equivlent in powershell especially on the argument part ?
>
> Is the a wscript.quit equivalent ?
>
> As for the rest, i assume write-host can be used for the wscript.echo
> parts.
>
>
>
>
>
>


My System SpecsSystem Spec
Old 01-10-2007   #3 (permalink)
Brandon Shell
Guest


 

Re: error checking

To be more specific... My example was just testing for any arguments. If you
want to test for a specific amount.

if(!($args -eq 2)){Write-Host "Bleh bleh bleh";Break}

"Brandon Shell" <tshell@mask.gmail.com> wrote in message
news:uB9DtiSNHHA.1008@TK2MSFTNGP06.phx.gbl...
>I have notice that alot of your questions are about VBscript to PowerShell
>Translation.
> Think link maybe helpful:
> http://www.microsoft.com/technet/scr...t/default.mspx
>
> Now.. about your question:
>
> if(!$args){
> Write-Host "Syntax Error. Correct syntax is: ..."
> Break
> }
>
>
> "IT Staff" <jkklim@hotmail.com> wrote in message
> news:enx0qtRNHHA.2140@TK2MSFTNGP03.phx.gbl...
>> in vbscript, i usually have this :
>>
>> If Wscript.Arguments.Count <> 2 Then
>> Wscript.Echo "Syntax Error. Correct syntax is:"
>> Wscript.Echo
>> Wscript.Echo "cscript kb.vbs <drive:filename.ext> <kbxxxxx>"
>> Wscript.Quit
>> End If
>>
>> Now what is the equivlent in powershell especially on the argument part ?
>>
>> Is the a wscript.quit equivalent ?
>>
>> As for the rest, i assume write-host can be used for the wscript.echo
>> parts.
>>
>>
>>
>>
>>
>>

>


My System SpecsSystem Spec
Old 01-10-2007   #4 (permalink)
Maximilian Hänel
Guest


 

Re: error checking

Hi Brandon,

> if(!($args -eq 2)){Write-Host "Bleh bleh bleh";Break}


I guess you mean

if(!($args.Length -eq 2)
------------^

cu

Max
My System SpecsSystem Spec
Old 01-10-2007   #5 (permalink)
Brandon Shell
Guest


 

Re: error checking

Whoops... funny... I had it in my test... well .count anyway. I cant wait
till they release the vista version... I can test on my prod machine.

"Maximilian Hänel" <ngSpam@smjh.de> wrote in message
news:O4Hxw8SNHHA.2236@TK2MSFTNGP02.phx.gbl...
> Hi Brandon,
>
>> if(!($args -eq 2)){Write-Host "Bleh bleh bleh";Break}

>
> I guess you mean
>
> if(!($args.Length -eq 2)
> ------------^
>
> cu
>
> Max


My System SpecsSystem Spec
Old 01-11-2007   #6 (permalink)
RichS
Guest


 

Re: error checking

If you are doing a lot of VBScript to Powershell conversions you can download
a copy of the translation guide from here

http://www.microsoft.com/downloads/d...displaylang=en
--
Richard Siddaway

Please note that all scripts are supplied "as is" and with no warranty


"Brandon Shell" wrote:

> I have notice that alot of your questions are about VBscript to PowerShell
> Translation.
> Think link maybe helpful:
> http://www.microsoft.com/technet/scr...t/default.mspx
>
> Now.. about your question:
>
> if(!$args){
> Write-Host "Syntax Error. Correct syntax is: ..."
> Break
> }
>
>
> "IT Staff" <jkklim@hotmail.com> wrote in message
> news:enx0qtRNHHA.2140@TK2MSFTNGP03.phx.gbl...
> > in vbscript, i usually have this :
> >
> > If Wscript.Arguments.Count <> 2 Then
> > Wscript.Echo "Syntax Error. Correct syntax is:"
> > Wscript.Echo
> > Wscript.Echo "cscript kb.vbs <drive:filename.ext> <kbxxxxx>"
> > Wscript.Quit
> > End If
> >
> > Now what is the equivlent in powershell especially on the argument part ?
> >
> > Is the a wscript.quit equivalent ?
> >
> > As for the rest, i assume write-host can be used for the wscript.echo
> > parts.
> >
> >
> >
> >
> >
> >

>
>

My System SpecsSystem Spec
Old 01-11-2007   #7 (permalink)
Maximilian Hänel
Guest


 

Re: error checking

Hi Brandon,

> Whoops... funny... I had it in my test... well .count anyway.


To be honest, I wasn't sure if it still works without explicitly
checking against the Count or Length property. So here's what I used for
a quick testing:

PS > $a=1..2
PS > if($a -eq 2){"It works"}
It works

That's sooo nasty, isn't it? It seems that -eq behaves like -contains.
So I wasn't sure if you run in the same trap ;-)

> I cant
> wait till they release the vista version... I can test on my prod machine.


It's not a problem for me as I still work on XP for developing reasons
and before I switch to Vista I need a new machine anyway ;-)

cu

Max
My System SpecsSystem Spec
Old 01-11-2007   #8 (permalink)
Brandon Shell
Guest


 

Re: error checking

Ya... Ya... I meant to do that

--

Brandon Shell
---------------
Stop by my blog some time
http://mybsinfo.blogspot.com/
----------------------------------

"Maximilian Hänel" <ngSpam@smjh.de> wrote in message
news:OAGQbvXNHHA.448@TK2MSFTNGP04.phx.gbl...
> Hi Brandon,
>
>> Whoops... funny... I had it in my test... well .count anyway.

>
> To be honest, I wasn't sure if it still works without explicitly checking
> against the Count or Length property. So here's what I used for a quick
> testing:
>
> PS > $a=1..2
> PS > if($a -eq 2){"It works"}
> It works
>
> That's sooo nasty, isn't it? It seems that -eq behaves like -contains. So
> I wasn't sure if you run in the same trap ;-)
>
>> I cant wait till they release the vista version... I can test on my prod
>> machine.

>
> It's not a problem for me as I still work on XP for developing reasons and
> before I switch to Vista I need a new machine anyway ;-)
>
> cu
>
> Max


My System SpecsSystem Spec
Old 01-11-2007   #9 (permalink)
Marco Shaw
Guest


 

Re: error checking

> Now what is the equivlent in powershell especially on the argument part ?

Another good ref:
http://blogs.msdn.com/powershell/arc...rvariable.aspx


My System SpecsSystem Spec
Old 01-12-2007   #10 (permalink)
Marcel J. Ortiz [MSFT]
Guest


 

Re: error checking

Sure you did. Actually, I just wanted to say you don't want to do that
because it won't work for things that evaluate to false. For ex.

PS>$a = 0..2
PS>if ($a -eq 0) { "It works" }
PS>

A lot of the comparison operators work on collections and can be used for
filtering. If the left side is enumerable then the result of the comparison
will be all the items that return true for that comparison. Here are some
other examples:

PS>$a = -2..4
PS>$a -gt 2
3
4
PS>$a = 'foo','bar','baz'
PS>$a -match 'a'
bar
baz
PS>$a -notmatch 'a'
foo
PS>'foo','boo' -replace 'o', 'a'
faa
baa

Anyway... what's happening below is that the comparison returns 2 and that's
evaluated to true. But to be safe, if you are testing for a specific value
you should use -contains. That always returns a boolean value. Here's the
difference:

PS>-1..1 -eq 0
0
PS>-1..1 -contains 0
True


"Brandon Shell" <tshell.mask@gmail.com> wrote in message
news:ukdf7xYNHHA.3872@TK2MSFTNGP06.phx.gbl...
> Ya... Ya... I meant to do that
>
> --
>
> Brandon Shell
> ---------------
> Stop by my blog some time
> http://mybsinfo.blogspot.com/
> ----------------------------------
>
> "Maximilian Hänel" <ngSpam@smjh.de> wrote in message
> news:OAGQbvXNHHA.448@TK2MSFTNGP04.phx.gbl...
>> Hi Brandon,
>>
>>> Whoops... funny... I had it in my test... well .count anyway.

>>
>> To be honest, I wasn't sure if it still works without explicitly checking
>> against the Count or Length property. So here's what I used for a quick
>> testing:
>>
>> PS > $a=1..2
>> PS > if($a -eq 2){"It works"}
>> It works
>>
>> That's sooo nasty, isn't it? It seems that -eq behaves like -contains. So
>> I wasn't sure if you run in the same trap ;-)
>>
>>> I cant wait till they release the vista version... I can test on my prod
>>> machine.

>>
>> It's not a problem for me as I still work on XP for developing reasons
>> and before I switch to Vista I need a new machine anyway ;-)
>>
>> cu
>>
>> Max

>



My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for mail error OldieC Live Mail 2 05-28-2008 03:01 PM
problems when using error checking on C: HHantu Vista General 2 04-27-2008 12:42 PM
Send-FTP Script with Error Checking? Michael Trantas PowerShell 6 01-14-2008 07:30 AM
OS/C Drive error-checking trouble ALP Vista General 6 08-30-2007 08:14 PM
Drive Error-Checking =?Utf-8?B?ZGV4b3M=?= Vista hardware & devices 0 08-28-2006 09:59 PM


Update your Vista Drivers Update Your Drivers Now!!

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