There are no separate math functions in PowerShell. So when you need
to access a maths function such as Round or Sqrt, just call for the
System.Math. Have you ever wondered about the PowerShell double colon
(::),
then all is revealed, it means a static method.
Note 3: As an alternative I have used [Math] instead of
[System.Math]; the pair seem interchangeable.
Note 4: Incidentally, 'Round' calculates to the
nearest number, which means it will round up. Whereas Truncate just
chops off the decimal places. Thus:
Round $Num = 49.6814343. The result is: 50 Truncate $Num =
49.6814343. The result is: 49
Note 6: Observe the position of the 2, as in two
decimal places.
Note 7: Check the logic of PowerShell's brackets.
Note 8: Here [System.Math] has been
abbreviated to [Math]
Guy Recommends: Solarwinds' Free Bulk Import Tool
Import users from a spreadsheet. Just provide a list of the
users with their fields in the
top row, and save as .csv file. Then launch this FREE utility and match
your fields with AD's
attributes, click to import the users. Optionally, you can
provide the name of the OU where the new accounts will be born.
There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:
The secret of finding more static properties is employ Get-Member with
the -static parameter.
[System.IO.File] | Get-Member -Static
Note 10: Try substituting other objects for .File, for example, Path or DriveInfo.
Note 11: Other cmdlets have static properties for example,
Get-Process | Get-Member -Static
»
Summary of PowerShell Math Functions
When you need
to access a maths function such as Round or Truncate, just call for the
System.Math. PowerShell has no separate math functions. There is no
need to create an object for the Math class, simply employ a double colon
(::) before the method.
If you like this page then please share it with your friends
If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.
*
Custom Search
Guy Recommends: WMI Monitor and It's Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, Solarwinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.