Monday, September 23, 2019

Dynamic 365 license assigned users details


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Below Powershell script can be used to get the Dynamic 365 license user with date assigned 
# License details can be seen from https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/licensing-service-plan-reference

Import-Module MSOnline

$AzureAdCred = Get-Credential
Connect-MsolService -Credential $AzureAdCred

Connect-AzureAD -Credential $AzureAdCred


$Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss
 $LogFileName=([string]::Concat("C:\Temp\Output_D365_CustoemrEngagement_License-Activated " , $Datetime ,".csv"))
 New-Item  $LogFileName  -ItemType file

Add-Content $LogFileName -Value ([string]::Concat("User email" +","+ "License Assigned date"))

 Write-Host "Getting all user start.."

$users = Get-MsolUser -all | Where isLicensed -EQ $true
Write-Host "Getting all user done.."
Write-Host "Start serarching for license.."

Foreach ($user in $users)

{
    $intFlag = 0
    $assignedplans = (Get-AzureADuser -ObjectId $user.UserPrincipalName).assignedplans

    #$assignedplans = (Get-AzureADUser -Filter "userPrincipalName eq 'admin.sanjiv.kumar@Test.onmicrosoft.com'").assignedplans
    
    foreach ($assignedplan in $assignedplans)

    {

      # Customre engagement license     

       If (($assignedplan.ServicePlanId -eq "d56f3deb-50d8-465a-bedb-f079817ccac1") -and ($assignedplan.CapabilityStatus -eq "Enabled"))# Customre engagement license

        {

            Write-Host "$user.UserPrincipalName"+"--"+"$assignedplan.AssignedTimestamp" -ForegroundColor White
            Add-Content $LogFileName -Value ([string]::Concat($($user.UserPrincipalName) +","+ $($assignedplan.AssignedTimestamp)+","+ "DYNAMICS 365 CUSTOMER ENGAGEMENT License" ))
           

        }

        #Team member license
        If (($assignedplan.ServicePlanId -eq "f5aa7b45-8a36-4cd1-bc37-5d06dea98645") -and ($assignedplan.CapabilityStatus -eq "Enabled")) #Team member license

        {
         
            Write-Host "$user.UserPrincipalName"+"--"+"$assignedplan.AssignedTimestamp" -ForegroundColor Yellow  
            Add-Content $LogFileName -Value ([string]::Concat($($user.UserPrincipalName) +","+ $($assignedplan.AssignedTimestamp)+","+ "DYNAMICS 365 Team Member License " ))
           

        }

    }

    

}

No comments:

Post a Comment

HTML

Script:

JS