Abs


Definition: Returns the absolute value of a number.

 

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 doneed 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.Mathclass and the Absmethod. 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