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.
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.
相关文章推荐
- Add custom and listview web part to wiki page using powershell
- How do I write to files using cheerio and request in node?
- Add custom and listview web part to a page in wiki page using powershell
- 【翻译】How-To: Using the N* stack, part 1
- How To Print Using Custom Page Sizes on Windows NT and Windows 2000(VB6)
- How to read and save Images in a Sql Server Database using ADO.NET and C#
- 32-bit Assembler is Easy, why and how to develop using the assembler; start learning to program in Assembly now!
- How to install LAMP (Apache, PHP and MySQL in Linux) using Yum
- 【翻译】How-To: Using the N* Stack, part 4
- 【翻译】How-To: Using the N* Stack, part 3
- How to extract controlfiles, datafiles, and archived logs from SMR backupsets without using RMAN
- 【翻译】How-To: Using the N* Stack, part 2
- How To Display Hierarchical Data by Using Nested Repeater Controls and Visual C# .NET(ZT)
- How to make dll and lib using bakefile.
- zhuanzai: AJAX: How to create a "Processing" modal window using UpdateProgress and ModalPopup ASP.net AJAX controls
- How to Change the DBID and the DBNAME by using NID [ID 224266.1]
- How-To : Using EJB 3.0 and Java Persistence API with Spring in OC4J
- How to serialize and deserialize using C# .NET
- How to Do Everything with PHP and MySQL
- How to add, modify, or delete registry subkeys and values by using a registration entries (.reg) file