-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPBIFreeLicenses.ps1
70 lines (56 loc) · 3.41 KB
/
PBIFreeLicenses.ps1
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
61
62
63
64
65
66
67
68
69
70
# --------------------------------------------------------------------------------------#
# Title: Get free licenses from Azure
# Author: Guilherme Matheus
# Date: Script created on 18.07.2021
# Script and data info: This script can get free licenses from Azure
# --------------------------------------------------------------------------------------#
# Reference taken from the official link https://docs.microsoft.com/en-us/powershell/module/azuread/?view=azureadps-2.0
# To work, it is necessary to install some modules, link: https://docs.microsoft.com/pt-br/powershell/azure/azurerm/install-azurerm-ps?view=azurermps-6.13.0
# To execute the script without agreeing with the execution policy
Set-ExecutionPolicy Bypass -Scope Process
# Imports Azure modules
Import-Module AzureRM
Import-Module AzureAD
# Email and Azure account data to be able to connect
$PBIAdminUPN = “[email protected]”
$PBIAdminPW = “yourpassword”
$MyOrgTenantID = “your Azure tenant”
$MyOrgBIAppID = “your ID from your Azure app”
$MyOrgBIThumbprint = “thumbprint id”
# Run the credential according to the login, password and tenant ID above
$SecPasswd = ConvertTo-SecureString $PBIAdminPW -AsPlainText -Force
$myCred = New-Object System.Management.Automation.PSCredential($PBIAdminUPN,$SecPasswd)
Connect-AzureAD -TenantId “your Azure tenant” -Credential $myCred
# Defines the directory and name of the file to be exported to the CSV file
$RetrieveDate = Get-Date
$BasePath = "D:\Azure\"
$UserPBIProLicensesCSV = $BasePath + "PBIFree.csv"
# Get license users
$ADUsers = Get-AzureADUser -All $true | Select-Object ObjectId, ObjectType, CompanyName, Department, DisplayName, JobTitle, Mail, Mobile, `
SipProxyAddress, TelephoneNumber, UserPrincipalName, UserType, @{Name="Date Retrieved";Expression={$RetrieveDate}}
<#
See MS Licensing Service Plan reference:
https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/licensing-service-plan-reference
#>
# Service Plan ID for Power BI FREE licenses
$PBIFreeServicePlanID = "2049e525-b859-401b-b2a0-e0a31c4b1fe4"
# Retrieve and export users with professional licenses based on the Power BI Free Service Plan ID ($PBIFreeServicePlanID)
# Each line represents a service plan for a specific user. This license detail is filtered only for the Power BI FREE service plan ID.
$UserLicenseDetail = ForEach ($ADUser in $ADUsers)
{
$UserObjectID = $ADUser.ObjectId
$UPN = $ADUser.UserPrincipalName
$UserName = $ADUser.DisplayName
$UserDept = $ADUser.Department
$AccountEnabled = $ADUser.AccountEnabled
$AssignedTimestamp = $ADUser.AssignedTimestamp
$CapabilityStatus = $ADUser.CapabilityStatus
Get-AzureADUserLicenseDetail -ObjectId $UserObjectID -ErrorAction SilentlyContinue | `
Select-Object ObjectID, SkuPartNumber, @{Name="UserName";Expression={$UserName}},@{Name="UserPrincipalName";Expression={$UPN}}, `
@{Name="Department";Expression={$UserDept}},@{Name="RetrieveDate";Expression={$RetrieveDate}} -ExpandProperty ServicePlans
}
$ProUsers = $UserLicenseDetail | Where-Object {$_.ServicePlanId -eq $PBIFreeServicePlanID}
#Get-AzureADUserLicenseDetail -ObjectId $UserObjectID | Get-Member
#Get-AzureADSubscribedSku | Get-Member
#Get-AzureADUser | Get-Member
$ProUsers | Export-Csv $UserPBIProLicensesCSV -force -notypeinformation -Encoding UTF8