Converting VBScript's Abs Function

Definition: Returns the absolute value of a number.

Abs

For system administrators, VBScript’s Abs function, which returns the absolute value of a number, is like having a spare house key hidden somewhere in the backyard: most likely you’ll never use it, but if you ever do need a spare key (or an absolute value function), well …. Although Windows PowerShell doesn’t have a built-in method for returning the absolute value of a number you can achieve that result by using the .NET Framework’s System.Math class and the Abs method. This command assigns the absolute value of -15 to the variable $a:

$a = [math]::abs(-15)

When you run this command and then echo back the value of $a (something you can do simply by typing $a) you should get the following:

15

Return to the VBScript to Windows PowerShell home page