Hi all,
When we announced Microsoft.Xrm.Data.PowerShell in this article, we got some feedback that you want to run the module on Azure Automation. Yes we hear you and here comes the latest module which supports Azure Automation!
Please get the latest module from GitHub (Please download version 2.x)
What’s Azure Automation?
Before showing “how to” part, I will explain what is Azure Automation in case you do not know about it. You can consider Azure Automation as PaaS. It provides a place to run PowerShell scripts. You don’t have to worry about Operating Systems nor clustering for High Availability, nor Infrastructure. Azure Automation also provides various capabilities.
– You can upload your own modules.
– You can store variables such as Credential, String, etc.
– You can schedule the task.
– You can draft and run test session, before “publish” the script.
– Integration with services such as GitHub, your own services, etc.
Please find more detail about Azure Automation here.
Step by Step instructions
It’s time to play with it. Please follow the steps below to create your first script running on the cloud, which disables “Display welcome screen to users when they sign in” System Settings.
Create Azure Automation Account
1. Login to Azure Portal. If you do not have any Azure Subscription, please sign up for 30 days trial. http://portal.azure.com
2. Click Browse | Automation Accounts from the list and click “Add” in the list.
3. Check if correct Subscription is selected, then enter name. Then click “Create” button.
4. Go back to Automation Accounts list to confirm the account has been created.
Add Assets
Next step is to add Assets. Asset is a place where you store your own stuff, such as PowerShell modules and variables.
1. Open added Automation Account and click Assets.
2. Click Modules.
3. Click “Add a module” button.
4. Click folder icon to browse module.
5. Select Microsoft.Xrm.Data.PowerShell.zip which you download from GitHub, and click “OK”.
6. Next, add credential. Click Credentials.
7. Click “Add a credential” button.
8. Enter credential detail and click “Create”.
9. Lastly, add CRM Server URL. Click “Variables”.
10. Click “Add a variable” and enter CRM server URL as “string” variable. Click “Create”.
Create Runbook
Now you are ready to write first script! To do so, you need to create a runbook, which will contain your script.
1. Go back to your automation account blade, and click Runbooks.
2. Click “Add a runbook” button, and select “Create a new runbook”.
3. Enter a name as “SetNavigationTourOff” and select “PowerShell” from Runbook type, then click “Create”.
4. Once the runbook created, select the runbook and click Edit.
5. Firstly, you get credential and CRM Server URL from variables. Expand “ASSETS” | “Variables” and right click “CRM Server” variable. Then, select Add “Get Variables” to canvas menu, which inserts a script to get the variable.
6. Modify the script to store the result to $crmserver variable.
7. Expand “Credentials” and right click “CrmCred”, then select Add to canvas.
8. Change the script to store the result to $cred variable.
9. Next, you connect to your CRM organization. Expand “CMDLETS” | “Microsoft,Xrm.Data.PowerShell” and right click “Connect-CrmOnline”, then click “Add to canvas”. Modify the script to store the connection to $conn variable, and pass parameters you obtained above.
10. Lastly, put the following script to the canvas either by typing or from left menu. The entire script looks like this.
11. Click “Save” to save the change.
Test the runbook
Once you crafted the script, you need to test it.
1. Click “Test Pane” button.
2. Click “Start” to run the test, and wait until it’s completed.
3. Once completed, login to your CRM to see if “Display welcome screen to users when they sign in” System Settings has been disabled.
Publish the runbook
Once you confirmed it works as expected, you publish the script.
1. Click “Publish” button. Click “Yes” for confirmation dialog.
2. You can also set scheduling. Click “Schedule” button.
3. Create your schedule as you need.
Conclusion
Microsoft.Xrm.Data.PowerShell is compatible with cloud now, and you can bring everything to the cloud. You may still need VM or local computer if you need to keep running the script less than every hour though, as minimum scheduling period is an hour for Azure Automation as of now.
Ken
Premier Mission Critical/Premier Field Engineer
Microsoft Japan