您的位置:首页 > 运维架构 > Shell

How To Do Math Using PowerShell, Part 1 and Part 2

2016-11-16 15:14 323 查看
Pls lick the below link to read part1
https://redmondmag.com/articles/2015/02/18/math-using-powershell-part-1.aspx

OK, so enough of the .NET lesson. I think that the real question is how you can call a .NET class without being a professional developer.Remember when I said that it was easy to call a .NET class from PowerShell? I wasn't lying. All you have to do is to enclose the class name in brackets, enter two colons and then enter your mathematical expression. Suppose, for instance, that I wanted to know the square root of 64. The first thing that I would need to do is to specify the class name. It's technically System.Math, but we can just use Math. The class name looks like this: [Math]. Next we type two colons. Hence, any line of code that makes use of the Math class will start out like this:[Math]::It doesn't matter if you are calculating a square root or retrieving the value of PI, [Math]:: will always come before the expression.So all you need now is the expression. In this case it's SQRT(64). As such, the line of code looks like this:[Math]::SQRT(64)You can see the result in Figure 4.


=====================================================================
Pls lick the below link to read part2
https://redmondmag.com/articles/2015/02/23/powershell-math-2.aspx

The result list shown in the figure above is essentially a list of the math operators that we can use. For instance, we could use the Round method to round a number. You can see an example of this in Figure 6.

[Click on image for larger view.] Figure 6. You can use the Round method to round a number.
As you can see, the System.Math class makes it possible to go way beyond PowerShell's built-in math capabilities. Learning to use the System.Math class opens the door to creating much more powerful PowerShell scripts.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Powershell