Runbook - PowerShell to modify Azure AD Group Not working

Category: azure automation


EuroTechie2013 on Fri, 05 Jan 2018 15:49:56


 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 "*"} | 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 "*"} | 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?



Stanislav Zhelyazkov on Mon, 08 Jan 2018 08:28:38


Seems you do not have the module you want to try to use imported in Azure Automation. Azure Automation only has a few modules that are imported our of the box and the Azure AD isn't one of them. Also you are using old version on your local machine. Microsoft has switched to a new version of Azure AD module :

Mark this reply as answer if it was useful.

Azure lover on Mon, 08 Jan 2018 09:06:54

You could check this blog

Import MSOnline module to your automation account.

Also, see this answer.