{"id":6161,"date":"2015-09-24T11:34:27","date_gmt":"2015-09-24T09:34:27","guid":{"rendered":"http:\/\/dollarunderscore.azurewebsites.net\/?p=6161"},"modified":"2016-09-06T22:52:15","modified_gmt":"2016-09-06T20:52:15","slug":"managing-office-365-and-azure-ad-with-azure-automation","status":"publish","type":"post","link":"https:\/\/p0wershell.com\/?p=6161","title":{"rendered":"Managing Office 365 and Azure AD with Azure Automation"},"content":{"rendered":"<p><strong>Update:<\/strong><br \/>\nThe Windows Azure Active Directory Module that was in preview when this was posted has been released and can be deployed straight to Azure Automation from this page: <a href=\"http:\/\/www.powershellgallery.com\/packages\/MSOnline\/1.0\" target=\"_blank\">http:\/\/www.powershellgallery.com\/packages\/MSOnline\/1.0<\/a><\/p>\n<p><em>The original post follows:<\/em><\/p>\n<p>The <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/jj151815.aspx\" target=\"_blank\">Azure AD PowerShell module<\/a> have some dependencies that historically made it fail in Azure Automation. In fact, it&#8217;s the <a href=\"http:\/\/feedback.azure.com\/forums\/246290-azure-automation\/suggestions\/5894629-fix-dependencies-for-azure-active-directory-manage\" target=\"_blank\">most upvoted suggestion<\/a> for Azure Automation at the time of writing this.<\/p>\n<p>But very recently a <a href=\"https:\/\/connect.microsoft.com\/site1164\/\" target=\"_blank\">public preview of a new version<\/a> of the module was released where the authentication part has been changed to use <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/jj573266.aspx\" target=\"_blank\">ADAL<\/a> instead, which seems to fix this issue!<\/p>\n<p>This is how you can test it yourself:<\/p>\n<p>First, you need to uninstall any previous version of the module you might have. If you can, go ahead and uninstall the Microsoft Online Services Sign-In Assistant as well to make sure the new module works as expected (the dependency on this service is now removed).<\/p>\n<p>Then go to <a href=\"https:\/\/connect.microsoft.com\/site1164\/Downloads\/DownloadDetails.aspx?DownloadID=59185\" target=\"_blank\">the download page<\/a> for the preview version of module, download it and install it. The installation procedure is very simple:<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard1.png\" alt=\"Wizard1\" width=\"618\" height=\"483\" class=\"alignnone size-full wp-image-6181\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard1.png 618w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard1-300x234.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/a><\/p>\n<p>Click next&#8230;<\/p>\n<p><a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard2.png\" alt=\"Wizard2\" width=\"618\" height=\"483\" class=\"alignnone size-full wp-image-6191\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard2.png 618w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard2-300x234.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/a><\/p>\n<p>Read the license terms, and check the box if you agree. Click next again&#8230;<\/p>\n<p><a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard3.png\" alt=\"Wizard3\" width=\"618\" height=\"483\" class=\"alignnone size-full wp-image-6201\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard3.png 618w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard3-300x234.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/a><\/p>\n<p>Choose an installation path (this actually not where the module currently ends up though, just the EULA-file&#8230;).<\/p>\n<p><a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard4.png\" alt=\"Wizard4\" width=\"618\" height=\"483\" class=\"alignnone size-full wp-image-6211\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard4.png 618w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard4-300x234.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/a><\/p>\n<p>Click Install to begin the installation, and confirm the UAC-prompt if you get one.<\/p>\n<p><a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard5.png\" alt=\"Wizard5\" width=\"618\" height=\"483\" class=\"alignnone size-full wp-image-6221\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard5.png 618w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard5-300x234.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/a><\/p>\n<p>The installation runs&#8230;<\/p>\n<p><a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard6.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard6.png\" alt=\"Wizard6\" width=\"618\" height=\"483\" class=\"alignnone size-full wp-image-6231\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard6.png 618w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/Wizard6-300x234.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/a><\/p>\n<p>And finally, just click Finish and the module is installed.<\/p>\n<p>Now open a PowerShell prompt, and run the following commands:<br \/>\nImport-Module MSOnline<br \/>\nGet-Module MSOnline | Format-List<\/p>\n<p>In the property &#8220;Path&#8221;, you&#8217;ll see where the module was installed, in my case it was &#8220;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\&#8221;:<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleInstallPath.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleInstallPath.png\" alt=\"ModuleInstallPath\" width=\"1375\" height=\"512\" class=\"alignnone size-full wp-image-6381\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleInstallPath.png 1375w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleInstallPath-300x112.png 300w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleInstallPath-1024x381.png 1024w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleInstallPath-624x232.png 624w\" sizes=\"(max-width: 1375px) 100vw, 1375px\" \/><\/a><\/p>\n<p>Go to that folder and zip the folders MSOnline and MSOnlineExtended, easiest way is probably to right-click on the folder, choose &#8220;Send to&#8221;, and then &#8220;Compressed (zipped) folder&#8221;, do this for both (one at a time). Should look something like this:<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/SendToZip.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/SendToZip.png\" alt=\"SendToZip\" width=\"975\" height=\"858\" class=\"alignnone size-full wp-image-6241\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/SendToZip.png 975w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/SendToZip-300x264.png 300w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/SendToZip-624x549.png 624w\" sizes=\"(max-width: 975px) 100vw, 975px\" \/><\/a><\/p>\n<p>It will prompt you to place the zipped files on your desktop instead of the current folder, which is a good idea, so click &#8220;Yes&#8221; \ud83d\ude42<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/PlaceOnDesktop.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/PlaceOnDesktop.png\" alt=\"PlaceOnDesktop\" width=\"480\" height=\"157\" class=\"alignnone size-full wp-image-6251\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/PlaceOnDesktop.png 480w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/PlaceOnDesktop-300x98.png 300w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p>You can now import those zip-files into Azure Automation. I recommend that you do this in the classical portal (I&#8217;ve had some issues when importing modules in the preview portal).<\/p>\n<p>First, go to your automation account, then go to assets, and then click \u201cImport Module\u201d at the bottom:<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AzurePortal_ImportModule.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AzurePortal_ImportModule.png\" alt=\"AzurePortal_ImportModule\" width=\"768\" height=\"642\" class=\"alignnone size-full wp-image-5501\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AzurePortal_ImportModule.png 768w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AzurePortal_ImportModule-300x251.png 300w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AzurePortal_ImportModule-624x522.png 624w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<p>Browse to your zipped module and click open:<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AAPortalBrowseChooseModule.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AAPortalBrowseChooseModule.png\" alt=\"AAPortalBrowseChooseModule\" width=\"943\" height=\"592\" class=\"alignnone size-full wp-image-6301\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AAPortalBrowseChooseModule.png 943w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AAPortalBrowseChooseModule-300x188.png 300w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/AAPortalBrowseChooseModule-624x392.png 624w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/a><\/p>\n<p>Click complete in lower right corner:<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ImportModuleDialogClassicPortal.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ImportModuleDialogClassicPortal.png\" alt=\"ImportModuleDialogClassicPortal\" width=\"652\" height=\"454\" class=\"alignnone size-full wp-image-6331\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ImportModuleDialogClassicPortal.png 652w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ImportModuleDialogClassicPortal-300x209.png 300w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ImportModuleDialogClassicPortal-624x435.png 624w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/a><\/p>\n<p>Repeat for both modules. You can follow the process at the bottom of the page:<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleImporting.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleImporting.png\" alt=\"ModuleImporting\" width=\"1161\" height=\"243\" class=\"alignnone size-full wp-image-6341\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleImporting.png 1161w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleImporting-300x63.png 300w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleImporting-1024x214.png 1024w, https:\/\/p0wershell.com\/wp-content\/uploads\/2015\/09\/ModuleImporting-624x131.png 624w\" sizes=\"(max-width: 1161px) 100vw, 1161px\" \/><\/a><\/p>\n<p>When everything is done, you should be able to use the module in Azure Automation. A simple native PowerShell script runbook that just lists some users would look like this:<\/p>\n<p>[PowerShell]<br \/>\n$AzureCred = Get-AutomationPSCredential -Name &#8216;AzureADCred&#8217;<\/p>\n<p>Connect-MsolService -Credential $AzureCred<\/p>\n<p>Get-MsolUser<br \/>\n[\/PowerShell]<\/p>\n<p>To give you an idea of how to assign a license:<br \/>\n[PowerShell]<br \/>\n$AzureCred = Get-AutomationPSCredential -Name &#8216;AzureADCred&#8217;<\/p>\n<p>Connect-MsolService -Credential $AzureCred<\/p>\n<p>$UserPrincipalName = &#8216;anders@mytenant.onmicrosoft.com&#8217;<br \/>\n$AccountSkuId = &#8216;mytenant:O365_BUSINESS_PREMIUM&#8217;<\/p>\n<p>$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId -DisabledPlans $null<\/p>\n<p>Set-MsolUserLicense -UserPrincipalName $UserPrincipalName -LicenseOptions $LicenseOptions -AddLicenses $AccountSkuId<br \/>\n[\/PowerShell]<\/p>\n<p>I haven&#8217;t tested the preview module fully in Azure Automation yet, but so far it seems to work fine (adding licenses and so on works!). Try it yourself and share your experiences!<\/p>\n<p>Happy automating Azure AD with Azure Automation \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update: The Windows Azure Active Directory Module that was in preview when this was posted has been released and can be deployed straight to Azure Automation from this page: http:\/\/www.powershellgallery.com\/packages\/MSOnline\/1.0 The original post follows: The Azure AD PowerShell module have some dependencies that historically made it fail in Azure Automation. In fact, it&#8217;s the most [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1171,111],"tags":[1201],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3Zj0A-1Bn","_links":{"self":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts\/6161"}],"collection":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6161"}],"version-history":[{"count":0,"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts\/6161\/revisions"}],"wp:attachment":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}