- Powershell Core 6.2 Cookbook
- Jan Hendrik Peters
- 219字
- 2021-06-24 15:14:33
How it works...
Static members of classes often contain helper methods and useful properties. There is one static method that most people with even a very short background in programming will know of, and that is public static void main (string[] args), which is used as the main entry point in a program in Java and C#.
In this recipe, you have used various static methods and properties to your advantage. You started in Step 1 by accessing the static method Beep in the console class to emit a sound. While not necessarily very useful, it is an easy example of a static method, or a method that does not require an object to work.
In Step 2, you saw that Get-Member is also available for discovering static members of a class. Steps 3 to 5 showed you different useful static members for day-to-day tasks. In the last step, you saw that some static properties can even change the behavior of cmdlets. By modifying the SecurityProtocol property of the ServicePointManager class, you can change the behavior of Invoke-WebRequest and Invoke-RestMethod for an entire session.
It would take more than a single recipe to show you all the helpful .NET types you can encounter. So, just stop from time to time, use Get-Member -Static, and examine the output!