.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Azure >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Windows Azure - Cmdlets Usage

Posted By:Jean Paul       Posted Date: July 22, 2012    Points: 200    Category: Azure    URL: http://www.dotnetspark.com  

In this article we will learn more about Cmdlets Usage in Windows Azure
 

Windows Azure - Cmdlets Usage

In the previous article we have explored the Installation of:
  • Windows Azure Platform PowerShell Cmdlets
You can refer the article here.

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 its usage.

  1. Getting List of Cmdlets

For getting the list of Cmdlet in the loaded package, use Get-Command


Eg: Get-Command -Module WAPPSCmdlets



  1. Getting Help
For getting help on a command use Get-Help command followed by the Cmdlet name

Eg: Get-Help New-Deployment



  1. Gettting Help with Example

For getting help with example on a particular command use the –examples option


Eg: Get-Help New-Deployment –examples




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:

exit – To exit the PowerShell application

cls – To clear the PowerShell screen
echo – To display text on the screen

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 below.




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 > Thumbprint property)


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 here.

Summary


In this article we have experimented on:

  • Getting Help of Cmdlet
  • Getting Help with Examples of Cmdlet
  • Creating PowerShell Command Script
  • Using PowerShell Script Editor
  • Resolving Initial Errors in PowerShell
  • Using Cmdlets to get log
I hope this information is enough for going ahead and automate Azure tasks using the PowerShell Cmdlet and editor.

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend