In the previous article we have explored the Installation of:
You can refer the article
For continuing with this article you need to open the PowerShell window and
enter the command: Add-PSSnapin WAPPSCmdlets Cmdlets
Below are the list of Cmdlets and their usage.
Like -examples, there are options â€“detailed and
â€“full to get detailed and full help on the topic. Note: You can also get the common commands like:
Creating PowerShell Scripts
We can create PowerShell Script files. The default extension should be .ps1.
Place the following content inside a file named Command.ps1
Echo "Hello, World!" Editing PowerShell Scripts
We can edit the PowerShell script file using the Edit option as shown
On clicking the Edit option you can see the following PowerShell Editor.
On executing the script you will get the following error: "File cannot be loaded because the execution of scripts is
disabled on this system. Please see "get-help about_signing" for more details." Reason: The system settings restricts running PowerShell scripts. Solution: Open the PowerShell window in Administrator mode and run the
following command: Set-ExecutionPolicy Unrestricted Note: The Execution Policy supports Unrestricted, Signed and Remotely
Signed scripts. This ensures that an unauthorized script is not executed in the
system. Making policy to Unrestricted is not recommended by for learning
purposes it should be fine.
If you do not run in Administrator mode, you will get the following error: Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft
.PowerShell' is denied. Reason: The Local Machine registry key is being shared by all users of
system. So Administrative privilege is needed to modify it. Solution: Run the PowerShell in Administrator mode
After the above problems are resolved, you can see the following output from
Editor. Running PowerShell Command Script
In case you need to execute the script manually or through application, you can
use the following command. powershell.exe â€“noexit c:\temp\command.ps1
The option â€“noexit says to make the execution window remained to view the
results. Run the following command inside the Windows Run window and you can see
the following result.
We can create a windows command script (.cmd) using the above command and later
we executing the same with just a double click. Invoking a Cmdlet
We are now ready to test a real example of invoking a cmdlet. Cmdlet: Get-HostedServices piped with Get-HostedProperties Inputs: SubscriptionId, CertificateThumbprint
The first pane shows the script and the second pane shows the output.
In the script pane the first two lines are variables declaration and value
assign. The Certificate thumbprint can be obtained from Windows Azure Portal.
(Management Certificates > Subscriptions > Select the first child node >
In the above script the output of Get-HostedServices is piped with Get-HostedProperties.
This concludes the usage of Cmdlets. More Cmdlet can be experiment through the
Get-Help option. You can find more examples
In this article we have experimented on:
I hope this information is enough for going
ahead and automate Azure tasks using the PowerShell Cmdlet and editor.
Jean Paul is a Developer plus Architect working on Microsoft Technologies for the past 12 years. He is very much passionate in programming and his core skills are SharePoint, ASP.NET & C#.
In the academic side ... Read more
C# Corner. All contents are copyright of their authors.