<?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>Get-AzureADMSPrivilegedRoleAssignment Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/get-azureadmsprivilegedroleassignment/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/get-azureadmsprivilegedroleassignment/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Tue, 26 Oct 2021 23:18:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Get PIM Role Assignment Status For Azure AD Using Powershell</title>
		<link>https://thesysadminchannel.com/get-pim-role-assignment-status-for-azure-ad-using-powershell/</link>
					<comments>https://thesysadminchannel.com/get-pim-role-assignment-status-for-azure-ad-using-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Thu, 17 Jun 2021 03:52:05 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Get PIM Role Assignment Status For Azure AD Using Powershell]]></category>
		<category><![CDATA[Get-AzureADMSPrivilegedRoleAssignment]]></category>
		<category><![CDATA[Get-AzureADMSPrivilegedRoleDefinition]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=3157</guid>

					<description><![CDATA[<p>If you&#8217;re like me and you love to run reports to get valuable information for your tenant and settings, the get PIM role assignment status is the script for you. Recently I was running a report to audit user permissions&#8230; <a href="https://thesysadminchannel.com/get-pim-role-assignment-status-for-azure-ad-using-powershell/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/get-pim-role-assignment-status-for-azure-ad-using-powershell/">Get PIM Role Assignment Status For Azure AD 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 like me and you love to run reports to get valuable information for your tenant and settings, the get PIM role assignment status is the script for you.  Recently I was running a report to audit user permissions in Azure AD and realized that my data was off by a bit.  I knew some users were added to Privilege Identity Management (PIM) roles but they weren&#8217;t showing up in my report.<br />
&nbsp;</p>
<div id="blockquote1">
<strong>Note:</strong> Check <a href="https://thesysadminchannel.com/how-to-add-azure-ad-roles-using-powershell-with-pim/" rel="noopener" target="_blank">Add PIM Role Assignments</a> if you&#8217;re looking to add roles using Powershell
</div>
<p>&nbsp;</p>
<p>The reason they weren&#8217;t showing up is because I was using the <strong>Get-AzureADDirectoryRoleMember</strong> cmdlet and that only shows users with current or activated access.  If a user was not elevated in PIM, they basically didn&#8217;t have access so it skewing my results.</p>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-AzureADDirectoryRole-Users-Azure-AD.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-AzureADDirectoryRole-Users-Azure-AD.png" alt="Get AzureADDirectoryRole Users Azure AD" width="1339" height="605" class="aligncenter size-full wp-image-3158" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-AzureADDirectoryRole-Users-Azure-AD.png?v=1623734460 1339w, https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-AzureADDirectoryRole-Users-Azure-AD-1024x463.png?v=1623734460 1024w, https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-AzureADDirectoryRole-Users-Azure-AD-768x347.png?v=1623734460 768w" sizes="(max-width: 1339px) 100vw, 1339px" /></a></p>
<p>&nbsp;</p>
<p>To give you a better idea of what I&#8217;m talking about, the above is a sample of the Helpdesk Administrators role.  In the Azure AD GUI, the user is added as an eligible role, meaning he can elevate his just in time access.  However in Powershell, since the role is not activated, it is not going to display.</p>
<p>Therefore we are going to use the <strong>Get-AzureADMSPrivilegedRoleDefinition</strong> Azure AD cmdlet to display the list of roles available and the <strong>Get-AzureADMSPrivilegedRoleAssignment</strong> to filter for the user we&#8217;re specifying.</p>
<h2>Requirements for this script to work</h2>
<p>In order to make this work you&#8217;ll need the following:</p>
<ul>
<li> <strong>AzureADPreview Powershell module</strong>.</li>
</ul>
<p>I want to emphasize the &#8220;preview&#8221; in the name of the module.  Using just the regular AzureAD module is not not going to work so that&#8217;s something to keep in mind.</p>
<h2>Script Parameters</h2>
<h4>
<ul> UserPrincipalName</ul>
</h4>
<p>Specify the UserPrincipalName for the user you want to check roles for.  </p>
<h4>
<ul> RoleName</ul>
</h4>
<p>Specify the RoleName you want to filter for. This will display all PIM roles that are granted directly or through a group.</p>
<h4>
<ul> TenantId</ul>
</h4>
<p>By default it will use the TenantId from your current session.  If you&#8217;re connected to a multi-tenant, you can specify the tenant here.</p>
<h2>Get PIM Role Assignment Status For Azure AD Using Powershell</h2>
<p>By using this script you&#8217;ll be able to see all the people who have standing access as well as PIM eligible roles.</p>
<pre class="brush: powershell; title: ; notranslate">

Function Get-PIMRoleAssignment {
&lt;#
.SYNOPSIS
    This will check if a user is added to PIM or standing access.
    For updated help and examples refer to -Online version.

.NOTES
    Name: Get-PIMRoleAssignment
    Author: theSysadminChannel
    Version: 1.0
    DateCreated: 2021-May-15

.EXAMPLE
    Get-PIMRoleAssignment -UserPrincipalName blightyear@thesysadminchannel.com

.EXAMPLE
    Get-PIMRoleAssignment -RoleName 'Global Administrator'

.LINK
    https://thesysadminchannel.com/get-pim-role-assignment-status-for-azure-ad-using-powershell -
#&gt;

    [CmdletBinding()]
    param(
        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            ParameterSetName = 'User',
            Position  = 0
        )]
        [string[]]  $UserPrincipalName,


        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            ParameterSetName = 'Role',
            Position  = 1
        )]
        [Alias('DisplayName')]
        [ValidateSet(
            'Application Administrator',
            'Application Developer',
            'Attack Simulation Administrator',
            'Authentication Administrator',
            'Azure Information Protection Administrator',
            'Billing Administrator',
            'Cloud Device Administrator',
            'Compliance Administrator',
            'Conditional Access Administrator',
            'Device Managers',
            'Directory Readers',
            'Directory Writers',
            'Exchange Administrator',
            'Exchange Recipient Administrator',
            'Global Administrator',
            'Global Reader',
            'Helpdesk Administrator',
            'Intune Administrator',
            'License Administrator',
            'Message Center Privacy Reader',
            'Message Center Reader',
            'Power BI Administrator',
            'Power Platform Administrator',
            'Privileged Authentication Administrator',
            'Privileged Role Administrator',
            'Reports Reader',
            'Search Administrator',
            'Security Administrator',
            'Security Reader',
            'Service Support Administrator',
            'SharePoint Administrator',
            'Skype for Business Administrator',
            'Teams Administrator',
            'Teams Communications Administrator',
            'Teams Communications Support Engineer',
            'Teams Communications Support Specialist',
            'User Administrator'
        )]
        [string]    $RoleName,


        [string]    $TenantId
    )

    BEGIN {
        $SessionInfo = Get-AzureADCurrentSessionInfo -ErrorAction Stop
        if (-not ($PSBoundParameters.ContainsKey('TenantId'))) {
            $TenantId = $SessionInfo.TenantId
        }

        $AdminRoles = Get-AzureADMSPrivilegedRoleDefinition -ProviderId aadRoles -ResourceId $TenantId -ErrorAction Stop | select Id, DisplayName
        $RoleId = @{}
        $AdminRoles | ForEach-Object {$RoleId.Add($_.DisplayName, $_.Id)}
    }

    PROCESS {
        if ($PSBoundParameters.ContainsKey('UserPrincipalName')) {
            foreach ($User in $UserPrincipalName) {
                try {
                    $AzureUser = Get-AzureADUser -ObjectId $User -ErrorAction Stop | select DisplayName, UserPrincipalName, ObjectId
                    $UserRoles = Get-AzureADMSPrivilegedRoleAssignment -ProviderId aadRoles -ResourceId $TenantId -Filter &quot;subjectId eq '$($AzureUser.ObjectId)'&quot;

                    if ($UserRoles) {
                        foreach ($Role in $UserRoles) {
                            $RoleObject = $AdminRoles | Where-Object {$Role.RoleDefinitionId -eq $_.id}

                            [PSCustomObject]@{
                                UserPrincipalName = $AzureUser.UserPrincipalName
                                AzureADRole       = $RoleObject.DisplayName
                                PIMAssignment     = $Role.AssignmentState
                                MemberType        = $Role.MemberType
                            }
                        }
                    }
                } catch {
                    Write-Error $_.Exception.Message
                }
            }
        }

        if ($PSBoundParameters.ContainsKey('RoleName')) {
            try {
                $RoleMembers = @()
                $RoleMembers += Get-AzureADMSPrivilegedRoleAssignment -ProviderId aadRoles -ResourceId $TenantId -Filter &quot;RoleDefinitionId eq '$($RoleId[$RoleName])'&quot; -ErrorAction Stop | select RoleDefinitionId, SubjectId, StartDateTime, EndDateTime, AssignmentState, MemberType

                if ($RoleMembers) {
                    $RoleMemberList = $RoleMembers.SubjectId | select -Unique
                    $AzureUserList = foreach ($Member in $RoleMemberList) {
                        try {
                            Get-AzureADUser -ObjectId $Member | select ObjectId, UserPrincipalName
                        } catch {
                            Get-AzureADGroup -ObjectId $Member | select ObjectId, @{Name = 'UserPrincipalName'; Expression = { &quot;$($_.DisplayName) (Group)&quot; }}
                            $GroupMemberList = Get-AzureADGroupMember -ObjectId $Member | select ObjectId, UserPrincipalName
                            foreach ($GroupMember in $GroupMemberList) {
                                $RoleMembers += Get-AzureADMSPrivilegedRoleAssignment -ProviderId aadRoles -ResourceId $TenantId -Filter &quot;RoleDefinitionId eq '$($RoleId[$RoleName])' and SubjectId eq '$($GroupMember.objectId)'&quot; -ErrorAction Stop | select RoleDefinitionId, SubjectId, StartDateTime, EndDateTime, AssignmentState, MemberType
                            }
                            Write-Output $GroupMemberList
                        }
                    }

                    $AzureUserList = $AzureUserList | select ObjectId, UserPrincipalName -Unique
                    $AzureUserHash = @{}
                    $AzureUserList | ForEach-Object {$AzureUserHash.Add($_.ObjectId, $_.UserPrincipalName)}

                    foreach ($Role in $RoleMembers) {
                        [PSCustomObject]@{
                            UserPrincipalName = $AzureUserHash[$Role.SubjectId]
                            AzureADRole       = $RoleName
                            PIMAssignment     = $Role.AssignmentState
                            MemberType        = $Role.MemberType
                        }
                    }
                }
            } catch {
                Write-Error $_.Exception.Message
            }
        }
    }

    END {}

}

</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-PIM-Role-Assignment-Azure-AD-Using-Powershell-1.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-PIM-Role-Assignment-Azure-AD-Using-Powershell-1.png" alt="Get PIM Role Assignment Azure AD Using Powershell" width="1001" height="449" class="aligncenter size-full wp-image-3335" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-PIM-Role-Assignment-Azure-AD-Using-Powershell-1.png?v=1629241342 1001w, https://thesysadminchannel.com/wp-content/uploads/2021/06/Get-PIM-Role-Assignment-Azure-AD-Using-Powershell-1-768x344.png?v=1629241342 768w" sizes="(max-width: 1001px) 100vw, 1001px" /></a></p>
<p>&nbsp;</p>
<p>We can now see that the Helpdesk Administrator is now showing up in our output and in the Assignment column it is labeled as Eligible.  We&#8217;ll also take note that we can see if the member type is added through a group or if it was added directly.  This script will support that option.</p>
<h2>Conclusion</h2>
<p>Get PIM role assignment status for Azure AD using Powershell will now be in your arsenal of cool tips and tricks for your Syadmin role. If you&#8217;re interested in more scripts like this, be sure to check out our <a href="https://thesysadminchannel.com/powershell/" rel="noopener" target="_blank">Powershell Gallery</a> or <a href="https://thesysadminchannel.com/azure/" rel="noopener" target="_blank">Azure Content</a>. Finally, be sure to check out our <a href="https://www.youtube.com/c/theSysadminChannel" rel="noopener" target="_blank">Youtube Channel</a> for any video content. </p>
<p>The post <a href="https://thesysadminchannel.com/get-pim-role-assignment-status-for-azure-ad-using-powershell/">Get PIM Role Assignment Status For Azure AD Using Powershell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/get-pim-role-assignment-status-for-azure-ad-using-powershell/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3157</post-id>	</item>
	</channel>
</rss>
