diff --git a/Find M365 Subscriptions Expiry Date/LicenseFriendlyName.txt b/Find M365 Subscriptions Expiry Date/LicenseFriendlyName.txt new file mode 100644 index 0000000..b062240 --- /dev/null +++ b/Find M365 Subscriptions Expiry Date/LicenseFriendlyName.txt @@ -0,0 +1,126 @@ + + O365_BUSINESS_ESSENTIALS = Office 365 Business Essentials + O365_BUSINESS_PREMIUM = Office 365 Business Premium + DESKLESSPACK = Office 365 (Plan K1) + DESKLESSWOFFPACK = Office 365 (Plan K2) + LITEPACK = Office 365 (Plan P1) + EXCHANGESTANDARD = Office 365 Exchange Online Only + STANDARDPACK = Enterprise Plan E1 + STANDARDWOFFPACK = Office 365 (Plan E2) + ENTERPRISEPACK = Enterprise Plan E3 + ENTERPRISEPACKLRG = Enterprise Plan E3 + ENTERPRISEWITHSCAL = Enterprise Plan E4 + STANDARDPACK_STUDENT = Office 365 (Plan A1) for Students + STANDARDWOFFPACKPACK_STUDENT = Office 365 (Plan A2) for Students + ENTERPRISEPACK_STUDENT = Office 365 (Plan A3) for Students + ENTERPRISEWITHSCAL_STUDENT = Office 365 (Plan A4) for Students + STANDARDPACK_FACULTY = Office 365 (Plan A1) for Faculty + STANDARDWOFFPACKPACK_FACULTY = Office 365 (Plan A2) for Faculty + ENTERPRISEPACK_FACULTY = Office 365 (Plan A3) for Faculty + ENTERPRISEWITHSCAL_FACULTY = Office 365 (Plan A4) for Faculty + ENTERPRISEPACK_B_PILOT = Office 365 (Enterprise Preview) + STANDARD_B_PILOT = Office 365 (Small Business Preview) + VISIOCLIENT = Visio Pro Online + POWER_BI_ADDON = Office 365 Power BI Addon + POWER_BI_INDIVIDUAL_USE = Power BI Individual User + POWER_BI_STANDALONE = Power BI Stand Alone + POWER_BI_STANDARD = Power-BI Standard + PROJECTESSENTIALS = Project Lite + PROJECTCLIENT = Project Professional + PROJECTONLINE_PLAN_1 = Project Online + PROJECTONLINE_PLAN_2 = Project Online and PRO + ProjectPremium = Project Online Premium + ECAL_SERVICES = ECAL + EMS = Enterprise Mobility Suite + RIGHTSMANAGEMENT_ADHOC = Windows Azure Rights Management + MCOMEETADV = PSTN conferencing + SHAREPOINTSTORAGE = SharePoint storage + PLANNERSTANDALONE = Planner Standalone + CRMIUR = CMRIUR + BI_AZURE_P1 = Power BI Reporting and Analytics + INTUNE_A = Windows Intune Plan A + PROJECTWORKMANAGEMENT = Office 365 Planner Preview + ATP_ENTERPRISE = Exchange Online Advanced Threat Protection + EQUIVIO_ANALYTICS = Office 365 Advanced eDiscovery + AAD_BASIC = Azure Active Directory Basic + RMS_S_ENTERPRISE = Azure Active Directory Rights Management + AAD_PREMIUM = Azure Active Directory Premium + MFA_PREMIUM = Azure Multi-Factor Authentication + STANDARDPACK_GOV = Microsoft Office 365 (Plan G1) for Government + STANDARDWOFFPACK_GOV = Microsoft Office 365 (Plan G2) for Government + ENTERPRISEPACK_GOV = Microsoft Office 365 (Plan G3) for Government + ENTERPRISEWITHSCAL_GOV = Microsoft Office 365 (Plan G4) for Government + DESKLESSPACK_GOV = Microsoft Office 365 (Plan K1) for Government + ESKLESSWOFFPACK_GOV = Microsoft Office 365 (Plan K2) for Government + EXCHANGESTANDARD_GOV = Microsoft Office 365 Exchange Online (Plan 1) only for Government + EXCHANGEENTERPRISE_GOV = Microsoft Office 365 Exchange Online (Plan 2) only for Government + SHAREPOINTDESKLESS_GOV = SharePoint Online Kiosk + EXCHANGE_S_DESKLESS_GOV = Exchange Kiosk + RMS_S_ENTERPRISE_GOV = Windows Azure Active Directory Rights Management + OFFICESUBSCRIPTION_GOV = Office ProPlus + MCOSTANDARD_GOV = Lync Plan 2G + SHAREPOINTWAC_GOV = Office Online for Government + SHAREPOINTENTERPRISE_GOV = SharePoint Plan 2G + EXCHANGE_S_ENTERPRISE_GOV = Exchange Plan 2G + EXCHANGE_S_ARCHIVE_ADDON_GOV = Exchange Online Archiving + EXCHANGE_S_DESKLESS = Exchange Online Kiosk + SHAREPOINTDESKLESS = SharePoint Online Kiosk + SHAREPOINTWAC = Office Online + YAMMER_ENTERPRISE = Yammer for the Starship Enterprise + EXCHANGE_L_STANDARD = Exchange Online (Plan 1) + MCOLITE = Lync Online (Plan 1) + SHAREPOINTLITE = SharePoint Online (Plan 1) + OFFICE_PRO_PLUS_SUBSCRIPTION_SMBIZ = Office ProPlus + EXCHANGE_S_STANDARD_MIDMARKET = Exchange Online (Plan 1) + MCOSTANDARD_MIDMARKET = Lync Online (Plan 1) + SHAREPOINTENTERPRISE_MIDMARKET = SharePoint Online (Plan 1) + OFFICESUBSCRIPTION = Office ProPlus + YAMMER_MIDSIZE = Yammer + DYN365_ENTERPRISE_PLAN1 = Dynamics 365 Customer Engagement Plan Enterprise Edition + ENTERPRISEPREMIUM_NOPSTNCONF = Enterprise E5 (without Audio Conferencing) + ENTERPRISEPREMIUM = Enterprise E5 (with Audio Conferencing) + MCOSTANDARD = Skype for Business Online Standalone Plan 2 + PROJECT_MADEIRA_PREVIEW_IW_SKU = Dynamics 365 for Financials for IWs + STANDARDWOFFPACK_IW_STUDENT = Office 365 Education for Students + STANDARDWOFFPACK_IW_FACULTY = Office 365 Education for Faculty + EOP_ENTERPRISE_FACULTY = Exchange Online Protection for Faculty + EXCHANGESTANDARD_STUDENT = Exchange Online (Plan 1) for Students + OFFICESUBSCRIPTION_STUDENT = Office ProPlus Student Benefit + STANDARDWOFFPACK_FACULTY = Office 365 Education E1 for Faculty + STANDARDWOFFPACK_STUDENT = Microsoft Office 365 (Plan A2) for Students + DYN365_FINANCIALS_BUSINESS_SKU = Dynamics 365 for Financials Business Edition + DYN365_FINANCIALS_TEAM_MEMBERS_SKU = Dynamics 365 for Team Members Business Edition + FLOW_FREE = Microsoft Flow Free + POWER_BI_PRO = Power BI Pro + O365_BUSINESS = Office 365 Business + DYN365_ENTERPRISE_SALES = Dynamics Office 365 Enterprise Sales + RIGHTSMANAGEMENT = Rights Management + PROJECTPROFESSIONAL = Project Professional + VISIOONLINE_PLAN1 = Visio Online Plan 1 + EXCHANGEENTERPRISE = Exchange Online Plan 2 + DYN365_ENTERPRISE_P1_IW = Dynamics 365 P1 Trial for Information Workers + DYN365_ENTERPRISE_TEAM_MEMBERS = Dynamics 365 For Team Members Enterprise Edition + CRMSTANDARD = Microsoft Dynamics CRM Online Professional + EXCHANGEARCHIVE_ADDON = Exchange Online Archiving For Exchange Online + EXCHANGEDESKLESS = Exchange Online Kiosk + SPZA_IW = App Connect + WINDOWS_STORE = Windows Store for Business + MCOEV = Microsoft Phone System + VIDEO_INTEROP = Polycom Skype Meeting Video Interop for Skype for Business + SPE_E5 = Microsoft 365 E5 + SPE_E3 = Microsoft 365 E3 + ATA = Advanced Threat Analytics + MCOPSTN2 = Domestic and International Calling Plan + FLOW_P1 = Microsoft Flow Plan 1 + FLOW_P2 = Microsoft Flow Plan 2 +DeveloperPack = Office 365 Enterprise E3 Developer Pack +DEVELOPERPACK_E5 = Office 365 Enterprise E5 Developer Pack +EMSPremium = Enterprise Mobility + Security E5 +RightsManagemnt =Azure Information Protection Plan 1 +DYN365_ENTERPRISE_CUSTOMER_SERVICE =Dynamics 365 for Customer Service Enterprise Edition +POWERFLOW_P1 = Microsoft PowerApps Plan 1 +POWERFLOW_P2 = Microsoft PowerApps Plan 2 +AAD_PREMIUM_P1 = Azure Active Directory Premium P2 +AAD_PREMIUM_P2 = Azure Active Directory Premium P2 +D365_MARKETING_USER = Microsoft Dynamics 365 Customer Engagement Plan +INFOPROTECTION_P2 = Azure Information Protection Plan 2 \ No newline at end of file diff --git a/Find M365 Subscriptions Expiry Date/M365SubscriptionExpiryDateReport.ps1 b/Find M365 Subscriptions Expiry Date/M365SubscriptionExpiryDateReport.ps1 new file mode 100644 index 0000000..160cb16 --- /dev/null +++ b/Find M365 Subscriptions Expiry Date/M365SubscriptionExpiryDateReport.ps1 @@ -0,0 +1,217 @@ +<# +============================================================================================= +Name: Get Microsoft 365 Subscription Expiry Date Report +Version: 1.0 + + +Script Highlights: +~~~~~~~~~~~~~~~~~~ + +1.Exports Office 365 license expiry date with ‘next lifecycle activity date’. +2.Exports report to the CSV file. +3.Result can be filtered based on soon to be expire license. ie, Licenses that are about to expire in 30 days. +4.Allows to filter out 'Purchased subscriptions' alone. +5.Subscription name is shown as user-friendly-name like ‘Office 365 Enterprise E3’ rather than ‘ENTERPRISEPACK’. +6.The script can be executed with MFA enabled account too. +7.The script supports Certificate based authentication too. +8.The script is scheduler friendly. + + +============================================================================================ +#> +Param +( + [Parameter(Mandatory = $false)] + + [switch]$CreateSession, + [string]$TenantId, + [string]$ClientId, + [string]$CertificateThumbprint, + [switch]$PurchasedSubscriptionsOnly, + [int]$SoonToExpireInDays +) + +Function Connect_MgGraph +{ + #Check for module installation + $Module=Get-Module -Name microsoft.graph.beta -ListAvailable + if($Module.count -eq 0) + { + Write-Host Microsoft Graph PowerShell SDK is not available -ForegroundColor yellow + $Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No + if($Confirm -match "[yY]") + { + Write-host "Installing Microsoft Graph PowerShell module..." + Install-Module Microsoft.Graph.beta -Repository PSGallery -Scope CurrentUser -AllowClobber -Force + } + else + { + Write-Host "Microsoft Graph Beta PowerShell module is required to run this script. Please install module using Install-Module Microsoft.Graph cmdlet." + Exit + } + } + #Disconnect Existing MgGraph session + if($CreateSession.IsPresent) + { + Disconnect-MgGraph + } + + + Write-Host Connecting to Microsoft Graph... + if(($TenantId -ne "") -and ($ClientId -ne "") -and ($CertificateThumbprint -ne "")) + { + Connect-MgGraph -TenantId $TenantId -AppId $ClientId -CertificateThumbprint $CertificateThumbprint -NoWelcome + } + else + { + Connect-MgGraph -Scopes "Directory.Read.All" -NoWelcome + } +} + +Connect_MgGraph + +$Result="" +$Results=@() + +$PrintedOutput=0 + +#Output file declaration +$Location=Get-Location +$ExportCSV="$Location\M365SubscriptionExpiryReport_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv" + +#Check for filters + + +#FriendlyName list for license plan +$FriendlyNameHash=@() +$FriendlyNameHash=Get-Content -Raw -Path .\LicenseFriendlyName.txt -ErrorAction Stop | ConvertFrom-StringData + + +#Get next lifecycle date + +$SubscriptionDetails=(Invoke-MgGraphRequest -Uri https://graph.microsoft.com/V1.0/directory/subscriptions -Method Get).Value + + +#Get available subscriptions in the tenant +foreach ($Subscription in $SubscriptionDetails) +{ + $SubscriptionName=$Subscription.SKUPartNumber + $SkuId=$Subscription.SkuId + $SubscribedOn=$Subscription.createdDateTime + $Status=$Subscription.status + $TotalLicenses=$Subscription.totalLicenses + $ExpiryDate=$Subscription.nextLifeCycleDateTime + $Print=1 + + #Determine subscription type + if(($ExpiryDate -eq $null)) + { + $SubscriptionType="Free/Trial" + } + else + { + $SubscriptionType="Purchased" + } + + #Filter for purchased licenses + if(($PurchasedSubscriptionsOnly.IsPresent) -and ($SubscriptionType -ne "Purchased")) + { + $Print=0 + } + + + #Convert Skuid to friendly name + $EasyName=$FriendlyNameHash[$SubscriptionName] + if(!($EasyName)) + { + $NamePrint=$SubscriptionName + } + else + { + $NamePrint=$EasyName + } + + #Convert Subscribed date to friendly subscribed date + $SubscribedDate=(New-TimeSpan -Start $SubscribedOn -End (Get-Date)).Days + if($SubscribedDate -eq 0) + { + $SubscribedDate="Today" + } + else + { + $SubscribedDate="$SubscribedDate days ago" + } + $SubscribedDate="(" + $SubscribedDate + ")" + $SubscribedDate="$SubscribedOn $SubscribedDate" + + + + + #Friendly Expiry Date + if($ExpiryDate -ne $null) + { + $FriendlyExpiryDate=(New-TimeSpan -Start (Get-Date) -End $ExpiryDate).Days + if($Status -eq "Enabled") + { + $FriendlyExpiryDate="Will expire in $FriendlyExpiryDate days" + } + elseif($Status -eq "Warning") + { + $FriendlyExpiryDate="Expired.Will suspend in $FriendlyExpiryDate days" + } + elseif($Status -eq "Suspended") + { + $FriendlyExpiryDate="Expired.Will delete in $FriendlyExpiryDate days" + } + elseif($Status -eq "LockedOut") + { + $FriendlyExpiryDate="Subscription is locked.Please contact Microsoft" + } + } + else + { + $ExpiryDate="-" + $FriendlyExpiryDate="Never Expires" + } + + #Filter for soon-to-expire subscriptions + if(($SoonToExpireInDays -ne "") -and ($ExpiryDate -ne $null) -and (($SoonToExpireInDays -lt $FriendlyExpiryDate))) + { + $Print=0 + } + + + #Export result to csv + + if($Print -eq 1) + { + $PrintedOutput++ + $Result=@{'Subscription Name'=$SubscriptionName;'SKU Id'=$SkuId;'Friendly Subscription Name'=$NamePrint;'Subscribed Date'=$SubscribedDate;'Total Units'=$TotalLicenses;'License Expiry Date/Next LifeCycle Activity Date'=$ExpiryDate;'Friendly Expiry Date'=$FriendlyExpiryDate;'Subscription Type'=$SubscriptionType;'Status'=$Status} + $Results= New-Object PSObject -Property $Result + $Results | Select-Object 'Subscription Name','Friendly Subscription Name','Subscribed Date','Total Units','Subscription Type','License Expiry Date/Next LifeCycle Activity Date','Friendly Expiry Date','Status','SKU Id' | Export-Csv -Path $ExportCSV -Notype -Append + } +} + +#Open output file after execution +if((Test-Path -Path $ExportCSV) -eq "True") +{ + Write-Host "" + Write-Host " Office 365 license expiry report available in:" -NoNewline -ForegroundColor Yellow + Write-Host $ExportCSV + Write-Host "" + Write-Host " The Output file contains:" -NoNewline -ForegroundColor Yellow + Write-Host $PrintedOutput subscriptions + Write-Host `n~~ Script prepared by AdminDroid Community ~~`n -ForegroundColor Green +Write-Host "~~ Check out " -NoNewline -ForegroundColor Green; Write-Host "admindroid.com" -ForegroundColor Yellow -NoNewline; Write-Host " to get access to 1800+ Microsoft 365 reports. ~~" -ForegroundColor Green `n`n + $Prompt = New-Object -ComObject wscript.shell + $UserInput = $Prompt.popup("Do you want to open output files?",` + 0,"Open Files",4) + If ($UserInput -eq 6) + { + Invoke-Item "$ExportCSV" + } +} +else +{ + Write-Host No subscription found. +} \ No newline at end of file