Azure Automation: Connect to Azure using PowerShell credential

Source: Internet
Author: User

Recently launched in the Chinese version of Windows Azure, with automation, you can import your own PowerShell scripts and then set up a run schedule so that the scripts can run as planned.

In this article, we'll learn how to use PowerShell credential to connect to a Azue subscription.

The summary process is as follows---

To prepare a user account:

1. To perform an automated task, it is recommended to create an account dedicated to execution automation, which we call Autouser.

2. Add Autouser to the co-administrator of Active Directory.

3. Log in with Autouser and change the password.

To create a configuration Automation account credential and subscription name:

1. Create an Automation account, which we call Testaccount.

2. Click Testaccount, click the Assets tab.

3. On the toolbar, click the Add Settings button.

4. In the Select the settings for the type to add page, click Add Credentials .

5. Select the credential type for Windows PowerShell credentials, and enter pscredential in the Name box.

6. Click Next, in the Define credentials window, in the User name box, enter the full name of the Autouser. In the Password and Confirm password box, enter the password that you changed.

7. Click Finish .

8. On the toolbar, click the Add Settings button.

9. In the Select a Settings page for the type you want to add, click Add Variable .

10. Select the string as the variable type, in the Name box, enter Subscriptionname, and click Next .

11. In the Value box, enter your subscription name, such as free trial, and click Finish .

Import PowerShell Script

1. Click the Runbook tab.

2. Click Import to save the following code: to your local file, such as D:\CONNECT2AZURE.PS1.

 workflow connect2azure{  $Credential  = get-automationpscredential-name     $SubscriptionName  = get-azureautomationvariable-name    #  connect to Azure  add-azureaccount-environment azurechinacloud-credential $ Credential  #  select the Azure Subscription to Workflow  select-azuresubscription-subscriptionname $ Subscriptionname   

Note : In the Chinese version of Windows Azure, you need to add a switch-environment when you use Add-azureaccount Azurechinacloud

3. In the Select Runbook to import, import the Connect2azure.ps1 file.

4. Click Connect2azure.

5. In Connect2azure, click the Authoring tab.

6. Review the code you have imported here. Here, you can edit, test, and publish your code.

Write your tasks:

Once you've connected to your Azure subscription, you can start adding your code, such as creating a storage account:

New-azurestorageaccount-location ' China North '-storageaccountname ' stor011 '

Add delay:

Start-sleep-seconds 60

Program schedule:

1. First, you need to publish your script first. Click Schedule, click Link to new schedule.

2. For a plan name, such as run18pm, click Next .

3. In the Configuration Schedule daily page, select Daily, at start time, enter 18:00.

4. Click Finish .

Your schedule will execute the job 18:00 every day.

Azure Automation: Connect to Azure using PowerShell credential

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.