Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's Abs Function

Windows PowerShell

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 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:


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft