-
Notifications
You must be signed in to change notification settings - Fork 15
/
Monitoring_License_Allocation.ps1
66 lines (49 loc) · 2.72 KB
/
Monitoring_License_Allocation.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
Set-Location c:\
Clear-Host
#We need the PowerShell module
Install-Module MSOnline -AllowClobber -Force -Verbose
#Lets connect
Connect-MsolService
#To find the unlicensed accounts in your organization
Get-MsolUser -All -UnlicensedUsersOnly
#To find accounts that don't have a UsageLocation value
Get-MsolUser -All | where {$_.UsageLocation -eq $null}
#View all users with Displayname and UsageLocation
Get-MsolUser -All | Format-Table DisplayName,Usagelocation -AutoSize
#List the licensing plans that are available in your organization
Get-MsolAccountSku
#List the services that are available in each licensing plan
(Get-MsolAccountSku | where {$_.AccountSkuId -eq "wechsler:ENTERPRISEPREMIUM"}).ServiceStatus
#This example shows the services to which the user jane.ford@tomwechsler.xyz has access
(Get-MsolUser -UserPrincipalName jane.ford@tomwechsler.xyz).Licenses.ServiceStatus
#Set UsageLocation for a specific user
Set-MsolUser -UserPrincipalName "info@wechsler.onmicrosoft.com" -UsageLocation CH
#Add a license for a specific user
Set-MsolUserLicense -UserPrincipalName "info@wechsler.onmicrosoft.com" -AddLicenses "wechsler:ENTERPRISEPREMIUM"
#Set a license for all unlicensed users (maybe not the best option - be careful)
Get-MsolUser -All -UnlicensedUsersOnly | Set-MsolUserLicense -AddLicenses "wechsler:ENTERPRISEPREMIUM"
#We investigate a department
Get-MsolUser -All -Department "Administration" -UnlicensedUsersOnly | Select-Object DisplayName, UsageLocation, Islicensed
#Set UsageLocation for a specific user
Set-MsolUser -UserPrincipalName "jane.dodge@tomwechsler.xyz" -UsageLocation CH
#A safer to add licenses to users
Get-MsolUser -All -Department "Administration" -UsageLocation "CH" -UnlicensedUsersOnly | Set-MsolUserLicense -AddLicenses "wechsler:ENTERPRISEPREMIUM"
#To view all the services for a user who has been assigned multiple licenses
$userUPN="jane.ford@tomwechsler.xyz"
$AllLicenses=(Get-MsolUser -UserPrincipalName $userUPN).Licenses
$licArray = @()
for($i = 0; $i -lt $AllLicenses.Count; $i++)
{
$licArray += "License: " + $AllLicenses[$i].AccountSkuId
$licArray += $AllLicenses[$i].ServiceStatus
$licArray += ""
}
$licArray
#Remove a license for a specific user
Set-MsolUserLicense -UserPrincipalName jane.ford@tomwechsler.xyz -RemoveLicenses "wechsler:ENTERPRISEPREMIUM"
#This removes all licenses from all user accounts in the Administration department in the Switzerland
$userArray = Get-MsolUser -All -Department "Administration" -UsageLocation "CH" | where {$_.isLicensed -eq $true}
for ($i=0; $i -lt $userArray.Count; $i++)
{
Set-MsolUserLicense -UserPrincipalName $userArray[$i].UserPrincipalName -RemoveLicenses $userArray[$i].licenses.accountskuid
}