0
votes

I'm using ARM and have created an automation account, with a run book using the PowerShell code snippet below to modify Azure AD users so that their location is updated properly. All resources are within the same subscription and resource group as my Azure AD.

get-msoluser | where{$_.userPrincipalName -like "*@contoso.co.uk"} | set-msoluser -Usagelocation "GB" When I run this in Azure, I get a failure as below:

The term 'get-msoluser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:2 char:1 + get-msoluser | where{$_.userPrincipalName -like "*@contoso.co.uk."} | s ... + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (get-msoluser:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

When I run the PowerShell manually using "connect-msolservice" and enter my credentials it works fine.

I have a couple of questions:

  1. Do I need to supply credentials so that the PowerShell knows which Azure AD to connect to?
  2. What modifications do I need to make to ensure get-msoluser cmdlet is recognised?

Thanks

1
This blog answered your question. Please see my answer.Shui shengbao

1 Answers

1
votes

You have to think about Azure Automation account as a fresh powershell install. it has got almost no modules in it. What you have to do first is install modules into it. Just follow that article and install the proper module, after that all the cmdlets from that module will be available to you in Azure Automation runbooks.

And you still need to authenticate against Azure AD (with proper rights) for your commands to work (else anybody could issue the same commands against your Azure AD, which is not something you would like). So you should start every runbook with the silent authentication commands. You can use Azure Automation variables to store passwords (to not hardcode them into the runbook).

You can also use certificate auth, Azure Automation is capable of storing certificates for that.