Skip to content

Commit

Permalink
Merge pull request #6 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
BNWEIN authored Jul 21, 2023
2 parents 9b54ca1 + b3e8d6b commit e011262
Show file tree
Hide file tree
Showing 14 changed files with 1,910 additions and 100 deletions.
1 change: 1 addition & 0 deletions AddAlert/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $Results = foreach ($Tenant in $tenants) {
NoCAConfig = [bool]$Request.body.NoCAConfig
SecDefaultsUpsell = [bool]$Request.body.SecDefaultsUpsell
SharePointQuota = [bool]$Request.body.SharePointQuota
ExpiringLicenses = [bool]$Request.body.ExpiringLicenses
type = 'Alert'
RowKey = $TenantID
PartitionKey = 'Alert'
Expand Down
1 change: 1 addition & 0 deletions ListAlertsQueue/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $CurrentStandards = foreach ($QueueFile in $QueuedApps) {
NoCAConfig = [bool]$QueueFile.NoCAConfig
SecDefaultsUpsell = [bool]$QueueFile.SecDefaultsUpsell
SharepointQuota = [bool]$QueueFile.SharePointQuota
ExpiringLicenses = [bool]$QueueFile.ExpiringLicenses
tenantId = $QueueFile.tenantid
}
}
Expand Down
36 changes: 4 additions & 32 deletions ListLicenses/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,23 @@ Write-Host 'PowerShell HTTP trigger function processed a request.'
# Interact with query parameters or the body of the request.
$TenantFilter = $Request.Query.TenantFilter
$RawGraphRequest = if ($TenantFilter -ne 'AllTenants') {
$LicRequest = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/subscribedSkus' -tenantid $TenantFilter
[PSCustomObject]@{
Tenant = $TenantFilter
Licenses = $LicRequest
}
$GraphRequest = Get-CIPPLicenseOverview -TenantFilter $TenantFilter
}
else {
$Table = Get-CIPPTable -TableName cachelicenses
$Rows = Get-AzDataTableEntity @Table | Where-Object -Property Timestamp -GT (Get-Date).AddHours(-1)
if (!$Rows) {
Push-OutputBinding -Name Msg -Value (Get-Date).ToString()
[PSCustomObject]@{
Tenant = 'Loading data for all tenants. Please check back in 1 minute'
Licenses = 'Loading data for all tenants. Please check back in 1 minute'
$GraphRequest = [PSCustomObject]@{
Tenant = 'Loading data for all tenants. Please check back in 1 minute'
License = 'Loading data for all tenants. Please check back in 1 minute'
}
}
else {
$GraphRequest = $Rows
}
}
Set-Location (Get-Item $PSScriptRoot).Parent.FullName
$ConvertTable = Import-Csv Conversiontable.csv
$LicenseTable = Get-CIPPTable -TableName ExcludedLicenses
$ExcludedSkuList = Get-AzDataTableEntity @LicenseTable
if (!$GraphRequest) {
$GraphRequest = foreach ($singlereq in $RawGraphRequest) {
$skuid = $singlereq.Licenses
foreach ($sku in $skuid) {
if ($sku.skuId -in $ExcludedSkuList.GUID) { continue }
$PrettyName = ($ConvertTable | Where-Object { $_.guid -eq $sku.skuid }).'Product_Display_Name' | Select-Object -Last 1
if (!$PrettyName) { $PrettyName = $sku.skuPartNumber }
[PSCustomObject]@{
Tenant = $singlereq.Tenant
License = $PrettyName
CountUsed = "$($sku.consumedUnits)"
CountAvailable = $sku.prepaidUnits.enabled - $sku.consumedUnits
TotalLicenses = "$($sku.prepaidUnits.enabled)"
skuId = $sku.skuId
skuPartNumber = $PrettyName
availableUnits = $sku.prepaidUnits.enabled - $sku.consumedUnits

}
}
}
}
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = @($GraphRequest)
Expand Down
51 changes: 9 additions & 42 deletions ListLicensesAllTenants/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,19 @@ $RawGraphRequest = Get-Tenants | ForEach-Object -Parallel {
$domainName = $_.defaultDomainName
Import-Module '.\GraphHelper.psm1'
Import-Module '.\Modules\AzBobbyTables'

Import-Module '.\Modules\CIPPCore'
try {
$Licrequest = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/subscribedSkus' -tenantid $_.defaultDomainName -ErrorAction Stop
[PSCustomObject]@{
Tenant = $domainName
Licenses = $Licrequest
}
Get-CIPPLicenseOverview -TenantFilter $domainName
}
catch {
[PSCustomObject]@{
Tenant = $domainName
Licenses = @{
skuid = "Could not connect to client"
skuPartNumber = "Could not connect to client"
consumedUnits = 0
prepaidUnits = { Enabled = 0 }
}
[pscustomobject]@{
Tenant = [string]$domainName
License = "Could not connect to client"
'PartitionKey' = 'License'
'RowKey' = "$($domainName) - Could not connect to client"
}
}
}
Set-Location (Get-Item $PSScriptRoot).Parent.FullName
$ConvertTable = Import-Csv Conversiontable.csv
$Table = Get-CIPPTable -TableName cachelicenses
$LicenseTable = Get-CIPPTable -TableName ExcludedLicenses
$ExcludedSkuList = Get-AzDataTableEntity @LicenseTable

$GraphRequest = foreach ($singlereq in $RawGraphRequest) {
$skuid = $singlereq.Licenses
foreach ($sku in $skuid) {
if ($sku.skuId -in $ExcludedSkuList.GUID) { continue }
$PrettyName = ($ConvertTable | Where-Object { $_.guid -eq $sku.skuid }).'Product_Display_Name' | Select-Object -Last 1
if (!$PrettyName) { $PrettyName = $sku.skuPartNumber }
@{
Tenant = "$($singlereq.Tenant)"
License = "$PrettyName"
CountUsed = "$($sku.consumedUnits)"
CountAvailable = "$($sku.prepaidUnits.enabled - $sku.consumedUnits)"
TotalLicenses = "$($sku.prepaidUnits.enabled)"
skuId = "$($sku.skuid)"
skuPartNumber = "$PrettyName"
availableUnits = "$($sku.prepaidUnits.enabled - $sku.consumedUnits)"
PartitionKey = 'License'
RowKey = "$($singlereq.Tenant) - $($sku.skuid)"
}
}
}

Write-Host "$($GraphRequest.RowKey) - $($GraphRequest.tenant)"
Add-AzDataTableEntity @Table -Entity $GraphRequest -Force | Out-Null
$Table = Get-CIPPTable -TableName cachelicenses
Add-AzDataTableEntity @Table -Entity $RawGraphRequest -Force | Out-Null
Loading

0 comments on commit e011262

Please sign in to comment.