mirror of
https://github.com/admindroid-community/powershell-scripts.git
synced 2025-12-17 16:35:19 +00:00
Update O365UserLicenseReport.ps1
Added country in the report
This commit is contained in:
parent
6ab47325d5
commit
6b5d4cee87
@ -1,4 +1,4 @@
|
|||||||
#Using this script administrator can identify all licensed users with their assigned licenses, services, and its status.
|
#Using this script administrator can identify all licensed users with their assigned licenses, services, and its status.
|
||||||
|
|
||||||
Param
|
Param
|
||||||
(
|
(
|
||||||
@ -11,24 +11,25 @@ Function Get_UsersLicenseInfo
|
|||||||
{
|
{
|
||||||
$LicensePlanWithEnabledService=""
|
$LicensePlanWithEnabledService=""
|
||||||
$FriendlyNameOfLicensePlanWithService=""
|
$FriendlyNameOfLicensePlanWithService=""
|
||||||
$upn=$_.userprincipalname
|
$upn=$_.userprincipalname
|
||||||
Write-Progress -Activity "`n Exported user count:$LicensedUserCount "`n"Currently Processing:$upn"
|
$Country=$_.Country
|
||||||
#Get all asssigned SKU for current user
|
Write-Progress -Activity "`n Exported user count:$LicensedUserCount "`n"Currently Processing:$upn"
|
||||||
$Skus=$_.licenses.accountSKUId
|
#Get all asssigned SKU for current user
|
||||||
|
$Skus=$_.licenses.accountSKUId
|
||||||
$LicenseCount=$skus.count
|
$LicenseCount=$skus.count
|
||||||
$count=0
|
$count=0
|
||||||
#Loop through each SKUid
|
#Loop through each SKUid
|
||||||
foreach($Sku in $Skus) #License loop
|
foreach($Sku in $Skus) #License loop
|
||||||
{
|
{
|
||||||
#Convert Skuid to friendly name
|
#Convert Skuid to friendly name
|
||||||
$LicenseItem= $Sku -Split ":" | Select-Object -Last 1
|
$LicenseItem= $Sku -Split ":" | Select-Object -Last 1
|
||||||
$EasyName=$FriendlyNameHash[$LicenseItem]
|
$EasyName=$FriendlyNameHash[$LicenseItem]
|
||||||
if(!($EasyName))
|
if(!($EasyName))
|
||||||
{$NamePrint=$LicenseItem}
|
{$NamePrint=$LicenseItem}
|
||||||
else
|
else
|
||||||
{$NamePrint=$EasyName}
|
{$NamePrint=$EasyName}
|
||||||
#Get all services for current SKUId
|
#Get all services for current SKUId
|
||||||
$Services=$_.licenses[$count].ServiceStatus
|
$Services=$_.licenses[$count].ServiceStatus
|
||||||
if(($Count -gt 0) -and ($count -lt $LicenseCount))
|
if(($Count -gt 0) -and ($count -lt $LicenseCount))
|
||||||
{
|
{
|
||||||
$LicensePlanWithEnabledService=$LicensePlanWithEnabledService+","
|
$LicensePlanWithEnabledService=$LicensePlanWithEnabledService+","
|
||||||
@ -39,9 +40,9 @@ Function Get_UsersLicenseInfo
|
|||||||
$serviceExceptDisabled=""
|
$serviceExceptDisabled=""
|
||||||
$FriendlyNameOfServiceExceptDisabled=""
|
$FriendlyNameOfServiceExceptDisabled=""
|
||||||
foreach($Service in $Services) #Service loop
|
foreach($Service in $Services) #Service loop
|
||||||
{
|
{
|
||||||
$flag=0
|
$flag=0
|
||||||
$ServiceName=$Service.ServicePlan.ServiceName
|
$ServiceName=$Service.ServicePlan.ServiceName
|
||||||
if($service.ProvisioningStatus -eq "Disabled")
|
if($service.ProvisioningStatus -eq "Disabled")
|
||||||
{
|
{
|
||||||
$DisabledServiceCount++
|
$DisabledServiceCount++
|
||||||
@ -56,17 +57,17 @@ Function Get_UsersLicenseInfo
|
|||||||
$serviceExceptDisabled =$serviceExceptDisabled+$ServiceName
|
$serviceExceptDisabled =$serviceExceptDisabled+$ServiceName
|
||||||
$flag=1
|
$flag=1
|
||||||
}
|
}
|
||||||
#Convert ServiceName to friendly name
|
#Convert ServiceName to friendly name
|
||||||
for($i=0;$i -lt $ServiceArray.length;$i +=2)
|
for($i=0;$i -lt $ServiceArray.length;$i +=2)
|
||||||
{
|
{
|
||||||
$ServiceFriendlyName = $ServiceName
|
$ServiceFriendlyName = $ServiceName
|
||||||
$Condition = $ServiceName -Match $ServiceArray[$i]
|
$Condition = $ServiceName -Match $ServiceArray[$i]
|
||||||
if($Condition -eq "True")
|
if($Condition -eq "True")
|
||||||
{
|
{
|
||||||
$ServiceFriendlyName=$ServiceArray[$i+1]
|
$ServiceFriendlyName=$ServiceArray[$i+1]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($flag -eq 1)
|
if($flag -eq 1)
|
||||||
{
|
{
|
||||||
if($EnabledServiceCount -ne 1)
|
if($EnabledServiceCount -ne 1)
|
||||||
@ -75,12 +76,12 @@ Function Get_UsersLicenseInfo
|
|||||||
}
|
}
|
||||||
$FriendlyNameOfServiceExceptDisabled =$FriendlyNameOfServiceExceptDisabled+$ServiceFriendlyName
|
$FriendlyNameOfServiceExceptDisabled =$FriendlyNameOfServiceExceptDisabled+$ServiceFriendlyName
|
||||||
}
|
}
|
||||||
#Store Service and its status in Hash table
|
#Store Service and its status in Hash table
|
||||||
$Result = @{'DisplayName'=$_.Displayname;'UserPrinciPalName'=$upn;'LicensePlan'=$Licenseitem;'FriendlyNameofLicensePlan'=$nameprint;'ServiceName'=$service.ServicePlan.ServiceName;
|
$Result = @{'DisplayName'=$_.Displayname;'UserPrinciPalName'=$upn;'LicensePlan'=$Licenseitem;'FriendlyNameofLicensePlan'=$nameprint;'ServiceName'=$service.ServicePlan.ServiceName;
|
||||||
'FriendlyNameofServiceName'=$serviceFriendlyName;'ProvisioningStatus'=$service.ProvisioningStatus}
|
'FriendlyNameofServiceName'=$serviceFriendlyName;'ProvisioningStatus'=$service.ProvisioningStatus}
|
||||||
$Results = New-Object PSObject -Property $Result
|
$Results = New-Object PSObject -Property $Result
|
||||||
$Results |select-object DisplayName,UserPrinciPalName,LicensePlan,FriendlyNameofLicensePlan,ServiceName,FriendlyNameofServiceName,
|
$Results |select-object DisplayName,UserPrinciPalName,LicensePlan,FriendlyNameofLicensePlan,ServiceName,FriendlyNameofServiceName,
|
||||||
ProvisioningStatus | Export-Csv -Path $ExportCSV -Notype -Append
|
ProvisioningStatus | Export-Csv -Path $ExportCSV -Notype -Append
|
||||||
}
|
}
|
||||||
if($Disabledservicecount -eq 0)
|
if($Disabledservicecount -eq 0)
|
||||||
{
|
{
|
||||||
@ -91,38 +92,38 @@ Function Get_UsersLicenseInfo
|
|||||||
$FriendlyNameOfLicensePlanWithService=$FriendlyNameOfLicensePlanWithService+ $NamePrint + "[" + $FriendlyNameOfServiceExceptDisabled +"]"
|
$FriendlyNameOfLicensePlanWithService=$FriendlyNameOfLicensePlanWithService+ $NamePrint + "[" + $FriendlyNameOfServiceExceptDisabled +"]"
|
||||||
#Increment SKUid count
|
#Increment SKUid count
|
||||||
$count++
|
$count++
|
||||||
}
|
}
|
||||||
$Output=@{'Displayname'=$_.Displayname;'UserPrincipalName'=$upn;'LicensePlanWithEnabledService'=$LicensePlanWithEnabledService;
|
$Output=@{'Displayname'=$_.Displayname;'UserPrincipalName'=$upn;Country=$Country;'LicensePlanWithEnabledService'=$LicensePlanWithEnabledService;
|
||||||
'FriendlyNameOfLicensePlanAndEnabledService'=$FriendlyNameOfLicensePlanWithService}
|
'FriendlyNameOfLicensePlanAndEnabledService'=$FriendlyNameOfLicensePlanWithService}
|
||||||
$Outputs= New-Object PSObject -Property $output
|
$Outputs= New-Object PSObject -Property $output
|
||||||
$Outputs | Select-Object Displayname,userprincipalname,LicensePlanWithEnabledService,FriendlyNameOfLicensePlanAndEnabledService | Export-Csv -path $ExportSimpleCSV -NoTypeInformation -Append
|
$Outputs | Select-Object Displayname,userprincipalname,Country,LicensePlanWithEnabledService,FriendlyNameOfLicensePlanAndEnabledService | Export-Csv -path $ExportSimpleCSV -NoTypeInformation -Append
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Function main()
|
Function main()
|
||||||
{
|
{
|
||||||
#Clean up session
|
#Clean up session
|
||||||
Get-PSSession | Remove-PSSession
|
Get-PSSession | Remove-PSSession
|
||||||
#Connect AzureAD from PowerShell
|
#Connect AzureAD from PowerShell
|
||||||
Connect-MsolService
|
Connect-MsolService
|
||||||
#Set output file
|
#Set output file
|
||||||
$ExportCSV=".\DetailedO365UserLicenseReport_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
$ExportCSV=".\DetailedO365UserLicenseReport_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
||||||
$ExportSimpleCSV=".\SimpleO365UserLicenseReport_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
$ExportSimpleCSV=".\SimpleO365UserLicenseReport_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
||||||
#FriendlyName list for license plan and service
|
#FriendlyName list for license plan and service
|
||||||
$FriendlyNameHash=Get-Content -Raw -Path .\LicenseFriendlyName.txt -ErrorAction Stop | ConvertFrom-StringData
|
$FriendlyNameHash=Get-Content -Raw -Path .\LicenseFriendlyName.txt -ErrorAction Stop | ConvertFrom-StringData
|
||||||
$ServiceArray=Get-Content -Path .\ServiceFriendlyName.txt -ErrorAction Stop
|
$ServiceArray=Get-Content -Path .\ServiceFriendlyName.txt -ErrorAction Stop
|
||||||
#Hash table declaration
|
#Hash table declaration
|
||||||
$Result=""
|
$Result=""
|
||||||
$Results=@()
|
$Results=@()
|
||||||
$output=""
|
$output=""
|
||||||
$outputs=@()
|
$outputs=@()
|
||||||
#Get licensed user
|
#Get licensed user
|
||||||
$LicensedUserCount=0
|
$LicensedUserCount=0
|
||||||
|
|
||||||
#Check for input file/Get users from input file
|
#Check for input file/Get users from input file
|
||||||
if([string]$UserNamesFile -ne "")
|
if([string]$UserNamesFile -ne "")
|
||||||
{
|
{
|
||||||
#We have an input file, read it into memory
|
#We have an input file, read it into memory
|
||||||
$UserNames=@()
|
$UserNames=@()
|
||||||
$UserNames=Import-Csv -Header "DisplayName" $UserNamesFile
|
$UserNames=Import-Csv -Header "DisplayName" $UserNamesFile
|
||||||
$userNames
|
$userNames
|
||||||
@ -146,13 +147,13 @@ Function main()
|
|||||||
#Open output file after execution
|
#Open output file after execution
|
||||||
Write-Host Detailed report available in: $ExportCSV
|
Write-Host Detailed report available in: $ExportCSV
|
||||||
Write-host Simple report available in: $ExportSimpleCSV
|
Write-host Simple report available in: $ExportSimpleCSV
|
||||||
$Prompt = New-Object -ComObject wscript.shell
|
$Prompt = New-Object -ComObject wscript.shell
|
||||||
$UserInput = $Prompt.popup("Do you want to open output files?",`
|
$UserInput = $Prompt.popup("Do you want to open output files?",`
|
||||||
0,"Open Files",4)
|
0,"Open Files",4)
|
||||||
If ($UserInput -eq 6)
|
If ($UserInput -eq 6)
|
||||||
{
|
{
|
||||||
Invoke-Item "$ExportCSV"
|
Invoke-Item "$ExportCSV"
|
||||||
Invoke-Item "$ExportSimpleCSV"
|
Invoke-Item "$ExportSimpleCSV"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
. main
|
. main
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user