<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Install Graph API module azure automation Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/install-graph-api-module-azure-automation/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/install-graph-api-module-azure-automation/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Fri, 06 Jan 2023 01:50:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Install Microsoft Graph Module for Azure Automation using PowerShell</title>
		<link>https://thesysadminchannel.com/install-microsoft-graph-module-for-azure-automation-using-powershell/</link>
					<comments>https://thesysadminchannel.com/install-microsoft-graph-module-for-azure-automation-using-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Fri, 06 Jan 2023 01:50:41 +0000</pubDate>
				<category><![CDATA[Azure Automation]]></category>
		<category><![CDATA[Graph API]]></category>
		<category><![CDATA[Install Graph API module azure automation]]></category>
		<category><![CDATA[Install Microsoft Graph Module for Azure Automation using PowerShell]]></category>
		<category><![CDATA[Microsoft Graph Module for Azure Automation]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=4662</guid>

					<description><![CDATA[<p>If you&#8217;re familiar with Azure Automation and Graph API, you may have noticed that it may be a bit cumbersome to install the Microsoft.Graph PowerShell module in an Automation account. Since the Graph API module has over 30 sub modules&#8230; <a href="https://thesysadminchannel.com/install-microsoft-graph-module-for-azure-automation-using-powershell/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/install-microsoft-graph-module-for-azure-automation-using-powershell/">Install Microsoft Graph Module for Azure Automation using PowerShell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you&#8217;re familiar with Azure Automation and Graph API, you may have noticed that it may be a bit cumbersome to install the Microsoft.Graph PowerShell module in an Automation account.  Since the Graph API module has over 30 sub modules it&#8217;s a bit of a pain to install the full set manually using the GUI.  Today we&#8217;re going to cover how to <strong>install the Microsoft Graph Module for Azure Automation using PowerShell</strong>.</p>
<div id="tableofcontents">
<h2>Table Of Contents</h2>
<ul>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#installmodule">Install Microsoft Graph Module for Azure Automation using PowerShell</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
</div>
<div id="requirements" style="scroll-margin-top: 15px;"></div>
<h2>Requirements</h2>
<p>Before I get to the script, there are a few things that need to be in place before we&#8217;re able to successfully install the module. Let&#8217;s cover that now:</p>
<ul>
<li>Az PowerShell Module</li>
<li>Permissions to install any module</li>
</ul>
<div id="installmodule" style="scroll-margin-top: 15px;"></div>
<h2>Install Microsoft Graph Module for Azure Automation using PowerShell</h2>
<p>Here is the script I wrote to be able to install and update the Microsoft.Graph module for an Automation account.  You can always manually check for the latest version on the <a href="https://www.powershellgallery.com/packages/Microsoft.Graph/" rel="noopener" target="_blank">PowerShell gallery</a>.</p>
<pre class="brush: powershell; title: ; notranslate">
#Before running the script, be sure you're on the right subscription
Set-AzContext -SubscriptionId $SubscriptionId
$ResourceGroup = 'rg-resourcegroupname'
$AutomationAccount = 'automationaccountname'
[System.Collections.Generic.List[Object]]$InstalledModules = @()

#Get top level graph module
$GraphModule = Find-Module Microsoft.Graph
$DependencyList = $GraphModule | select -ExpandProperty Dependencies | ConvertTo-Json | ConvertFrom-Json
$ModuleVersion = $GraphModule.Version

#Since we know the authentication module is a dependency, let us get that one first
$ModuleName = 'Microsoft.Graph.Authentication'
$ContentLink = &quot;https://www.powershellgallery.com/api/v2/package/$ModuleName/$ModuleVersion&quot;
New-AzAutomationModule -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccount -Name $ModuleName -ContentLinkUri $ContentLink -ErrorAction Stop | Out-Null
do {
    Start-Sleep 20
    $Status = Get-AzAutomationModule -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccount -Name $ModuleName | select -ExpandProperty ProvisioningState
} until ($Status -in ('Failed','Succeeded'))

if ($Status -eq 'Succeeded') {
    $InstalledModules.Add($ModuleName)

    foreach ($Dependency in $DependencyList) {
        $ModuleName = $Dependency.Name
        if ($ModuleName -notin $InstalledModules) {
            $ContentLink = &quot;https://www.powershellgallery.com/api/v2/package/$ModuleName/$ModuleVersion&quot;
            New-AzAutomationModule -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccount -ContentLinkUri $ContentLink -Name $ModuleName -ErrorAction Stop | Out-Null
            sleep 3
        }
    }

    $LoopIndex = 0
    do {
        foreach ($Dependency in $DependencyList) {
            $ModuleName = $Dependency.Name
            if ($ModuleName -notin $InstalledModules) {
                $Status = Get-AzAutomationModule -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccount -Name $ModuleName -ErrorAction SilentlyContinue | select -ExpandProperty ProvisioningState
                sleep 3
                if ($Status -in ('Failed','Succeeded')) {
                    if ($Status -eq 'Succeeded') {
                        $InstalledModules.Add($ModuleName)
                    }

                    [PSCustomObject]@{
                        Status           = $Status
                        ModuleName       = $ModuleName
                        ModulesInstalled = $InstalledModules.Count
                    }
                }
            }
        }
        $LoopIndex++
    } until (($InstalledModules.Count -ge $GraphModule.Dependencies.count) -or ($LoopIndex -ge 10))
}



</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Authentication-Module.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Authentication-Module.png" alt="Install Authentication Module" width="1200" height="438" class="aligncenter size-full wp-image-4666" srcset="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Authentication-Module.png 1200w, https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Authentication-Module-1024x374.png 1024w, https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Authentication-Module-768x280.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></a></p>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules.png" alt="Microsoft Graph Module for Azure Automation" width="1383" height="675" class="aligncenter size-full wp-image-4668" srcset="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules.png 1383w, https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules-1024x500.png 1024w, https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules-768x375.png 768w" sizes="(max-width: 1383px) 100vw, 1383px" /></a></p>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules-Start-PowerShell.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules-Start-PowerShell.png" alt="Microsoft Graph Module for Azure Automation" width="1394" height="556" class="aligncenter size-full wp-image-4667" srcset="https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules-Start-PowerShell.png 1394w, https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules-Start-PowerShell-1024x408.png 1024w, https://thesysadminchannel.com/wp-content/uploads/2023/01/Install-Graph-Modules-Start-PowerShell-768x306.png 768w" sizes="(max-width: 1394px) 100vw, 1394px" /></a></p>
<div id="conclusion" style="scroll-margin-top: 15px;"></div>
<h2>Conclusion</h2>
<p>And just like that, we were able to install the Microsoft Graph Module for Azure Automation. One thing to note, This method only supports PowerShell version 5.1 at the moment so if you want to install the module for PowerShell 7 and later, you will still need to do that the manual way.<br />
&nbsp;</p>
<p>Since you&#8217;re now using Graph API with Azure Automation, here is a great article to <a href="https://thesysadminchannel.com/graph-api-using-a-managed-identity-in-an-automation-runbook/" rel="noopener" target="_blank">use Managed Identities in your Automation Runbooks</a> so you no longer have to worry about secrets or certificates in your code.</p>
<p>The post <a href="https://thesysadminchannel.com/install-microsoft-graph-module-for-azure-automation-using-powershell/">Install Microsoft Graph Module for Azure Automation using PowerShell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/install-microsoft-graph-module-for-azure-automation-using-powershell/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4662</post-id>	</item>
	</channel>
</rss>
