![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
| | #5 (permalink) |
| 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 Specs![]() |
| | #6 (permalink) |
| 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 Specs![]() |
| | #7 (permalink) |
| 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 Specs![]() |
| | #8 (permalink) |
| 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 Specs![]() |
| | #9 (permalink) |
| 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 Specs![]() |
| | #10 (permalink) |
| Guest | Re: error checking Sure you did. Actually, I just wanted to say you don't want to do thatbecause 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 Specs![]() |
![]() |
| 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 |