Powershell – That torrid vbScript affair – Part 2

Powershell

Yes.  I am speaking vbScript in a blog that is Dominantly Powershell.  

Now all of you put down the burning torches, Rocks, Llamas and sacks of wet Cheetos.  There is no need for a mob scene.

We’re going to talk a little bit about vbScript (just a bit of Syntax) for Powershell people because there are a LOT of WMI based vbScript solutions out there.  Heck there are a TON of vbScript solutions out there.    It pays to remember a lot of brilliant people devised these solutions and their knowledge should not be ignored.

So you’re a Powershell guy and you’re trying to make a new “wheel”.  There are some things that are just so simple in Powershell, we don’t even think about looking further.

Then there are times (especially if you’re learning Powershell) you try to find a solution, all you can find is vbScript.   Well then. Translate that to Powershell!

Let’s look at a simple vbScript statement

CONST MYSERVER-NAME=’Server1’

Well if you’re working in Powershell that’s the same as doing a

SET-VARTIABLE $MYSERVER-NAME=’Server1’

But often in Powershell setting a permanent Global constant isn’t as necessary and we just do a

$MYSERVER-NAME=’Server1’

As well in vbScript you’ll often see a statement like this

SET FolderName=”C:Windows

In Powershell it’s a slight switch in Syntax

$FolderName=’C:Windows’

Really not such a huge headache to deal with.   Now one of the things I ran in to in vBscript were stuff like this

Const STUPIDNUMBER = &H48FF&

I originally couldn’t make heads or tales of this.  THIS was a ‘secret code’ in my world.  Well no, no it wasn’t.

It was a HexaDecimal number.   The two ‘& &’ are Delimiters in vbScript to indicate where this special non Decimal number starts and ends.   The “H” immediately after indicates the sequence of characters are a Hexadecimal number using the characters from 0 to F. Until it reaches the second ‘&’ this is a Hexadecimal number

Powershell, typing in such numbers is (I think personally) a little more direct.

0xHexadecimal number

So looking at

Const STUPIDNUMBER = &H48FF&

In Powershell would be

$STUPIDNUMBER = 0x48FF

We’ll look at a little bit more vbScript next time.  Just a bit.

Remember just because you love Powershell doesn’t mean you should scorn vbScript.   Embrace the knowledge from those before you and learn IT to shape the future.

Sean
The Energized Tech

Leave a Reply