<?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>Microsoft Graph | KC's Blog</title>
	<atom:link href="https://www.kjctech.net/tag/microsoft-graph/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kjctech.net</link>
	<description></description>
	<lastBuildDate>Fri, 14 Mar 2025 21:38:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.kjctech.net/wp-content/uploads/2016/12/cropped-KC-Logo.png?fit=32%2C32&#038;ssl=1</url>
	<title>Microsoft Graph | KC's Blog</title>
	<link>https://www.kjctech.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">24634607</site>	<item>
		<title>Managing Microsoft Licenses in PowerShell and Microsoft Graph</title>
		<link>https://www.kjctech.net/manage-microsoft-licenses-in-powershell-and-microsoft-graph/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=manage-microsoft-licenses-in-powershell-and-microsoft-graph</link>
					<comments>https://www.kjctech.net/manage-microsoft-licenses-in-powershell-and-microsoft-graph/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Fri, 14 Mar 2025 20:05:11 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Microsoft 365]]></category>
		<category><![CDATA[Microsoft Graph]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=5204</guid>

					<description><![CDATA[<p>Most of the time, I manage the licensing part of Microsoft 365 manually, but from time to time, using PowerShell can be easy and clean. To view account license and service details First, connect to Microsoft Graph. Connect-Graph To list all license plans you purchased with part number and ID, Get-MgSubscribedSku &#124; Select-Object SkuPartNumber, SkuID To list the services that [&#8230;]</p>
The post <a href="https://www.kjctech.net/manage-microsoft-licenses-in-powershell-and-microsoft-graph/">Managing Microsoft Licenses in PowerShell and Microsoft Graph</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>Most of the time, I manage the licensing part of Microsoft 365 manually, but from time to time, using PowerShell can be easy and clean.</p>



<h3 class="wp-block-heading">To view account license and service details</h3>



<p>First, connect to Microsoft Graph.</p>



<pre class="wp-block-preformatted">Connect-Graph</pre>



<p>To list all license plans you purchased with part number and ID,</p>



<pre class="wp-block-preformatted">Get-MgSubscribedSku | Select-Object SkuPartNumber, SkuID</pre>



<p>To list the services that are available in each license plan,</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">$allSKUs = Get-MgSubscribedSku
$allSKUs | ForEach-Object {
  "Service Plan: " + $_.SkuPartNumber
  $_.ServicePlans | Select-Object ServicePlanName, ServicePlanID
}</code></pre>



<p>To list all license plans assigned to a specific user,</p>



<pre class="wp-block-preformatted">Get-MgUserLicenseDetail -UserID $userID</pre>



<p>To list all services from all assigned license plans for a specific user,</p>



<pre class="wp-block-preformatted">(Get-MgUserLicenseDetail -UserID $userID -Property ServicePlans).ServicePlans</pre>



<p>Service plans can be quite messy if you manage them manually so using PowerShell could save a lot of time and could make things a lot easier.</p>



<h3 class="wp-block-heading">To assign or remove a license plan from a user account</h3>



<p>Now you need to sign in to Microsoft Graph with some extra permission scope.</p>



<pre class="wp-block-preformatted">Connect-MgGraph -Scopes User.ReadWrite.All</pre>



<p>You will also need to make sure the <strong><em>UsageLocation</em></strong> is set for the user before assigning any license plans, e.g. US for the United States and CA for Canada, etc. To find out all the accounts in your tenant that don&#8217;t have a <strong><em>UsageLocation</em></strong> value, run the command below.</p>



<pre class="wp-block-preformatted">Get-MgUser -Select Id,DisplayName,Mail,UserPrincipalName,UsageLocation,UserType | where { $_.UsageLocation -eq $null -and $_.UserType -eq 'Member' }</pre>



<p>To assign a license plan to a specific user,</p>



<pre class="wp-block-preformatted">Set-MgUserLicense  -UserID $userID -AddLicenses @{SkuID = $skuID} -RemoveLicenses @()</pre>



<p>You can retrieve the license SKUID like this, where $partNumber is the name of the license plan, such as SPB for Business Premium, etc.</p>



<pre class="wp-block-preformatted">$skuID = (Get-MgSubscribedSku -All | Where-Object SkuPartNumber -eq $partNumber).SkuID</pre>



<p>To remove a license plan from a specific user,</p>



<pre class="wp-block-preformatted">Set-MgUser-License -UserID $userID -RemoveLicenses @($skuID) -AddLicenses @()</pre>



<p>To remove all license plans from a specific user,</p>



<pre class="wp-block-preformatted">Get-MgUserLicenseDetail -UserId $userID | ForEach-Object {Set-MgUserLicense -Userid $userID -RemoveLicenses @($_.skuid) -AddLicenses @()}</pre>



<h4 class="wp-block-heading">References:</h4>



<ul class="wp-block-list">
<li><a href="https://learn.microsoft.com/en-us/microsoft-365/enterprise/view-licenses-and-services-with-microsoft-365-powershell?view=o365-worldwide">View Microsoft 365 Licenses and Services with PowerShell</a></li>
</ul>



<p></p>The post <a href="https://www.kjctech.net/manage-microsoft-licenses-in-powershell-and-microsoft-graph/">Managing Microsoft Licenses in PowerShell and Microsoft Graph</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/manage-microsoft-licenses-in-powershell-and-microsoft-graph/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5204</post-id>	</item>
	</channel>
</rss>
