Converting VBScript's Oct Function

Definition: Returns a string representing the octal value of a number.


As script writers, a question we always ask ourselves is this: where would we be without octal numbers?

Well, OK, good point. Still, you never know: maybe someday you will have to use Windows PowerShell to convert a decimal value to its octal equivalent. If and when that time comes you can do this using the .NET Framework Convert class and the ToString() method. Just pass ToString() two parameters:

  • The decimal value to be converted (in our sample command, 999).

  • The value 8 (the second parameter tells .NET to convert the value to its octal equivalent).

In other words, do something like this:

$a = [Convert]::ToString(999,8)

When you run this command and then echo back the value of $a you should get the following:


Return to the VBScript to Windows PowerShell home page