How it works...

The goal of this recipe is to demonstrate how PowerShell works hand-in-hand with .NET, and objects that are created the .NET way can be called (and stored) easily in PowerShell. First, we declare a class with the keyword, class. We then declare its parameters, and then, create two constructors: one default and one parameterised.

We also create a method called sal. We define its return type as int32, and defined two parameters. Within it, we define what needs to be returned.

Back at the PowerShell prompt, we call the static (method of the class, not of an object) New method. The syntax is to mention the class name, followed by two consecutive colons (::) to call it in the global namespace, followed by the name of the method.

If you follow the steps, you'll also see an example of using the two different system class libraries, System.Net.Mail.SmtpClient and System.Net.Mail.MailMessage, and the instantiation of a method by integrating the output of mail-message with the SMTP-client object.

Next, we use the system class library System.Management.Automation.PSCredential. In this example, we send some text to ConvertTo-SecureString which takes input as plain text and converts it to a secure string. Then, we pass the encrypted string to the PSCrendital system class to store the user name and the secure string into the $Credentials variable. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.182.179