I’m working on a dashboard which will show our current amount of Azure/365 licences purchase, the amount consumed and then the amount remaining. The basic function of all this is working OK, however the values for the counters are not updating when the page refreshes.
I assumed (perhaps incorrectly) that when a page is refreshed, any bits of code get re-run. Is this not the case?
I’ve been playing around with endpoints and cached variables to see if this would help things, but it isn’t at the moment.
Any suggestions would be greatly appreciated!
My dashboard:
$Theme = New-UDTheme -Name "Custom" -Definition @{
'nav' = @{
'background-color' = '#ff0028'
'display' = 'none'
}
'.page-footer' = @{
'background-color' = '#ff0028'
'display' = 'none'
}
'.row' = @{
'margin-bottom' = '10px'
}
'.card' = @{
'margin' = '.2rem 0 .5rem'
}
'.card-title' = @{
'font-size' = '28px !important'
'font-weight' = 'bold !important'
}
'.left-align' = @{
'font-size' = '40px'
}
}
$RequiredGroups = @(
"SG_License Advanced Threat Protection",
"SG_License EMS E3",
"SG_License Exchange Online Plan 1",
"SG_License Microsoft 365 E3",
"SG_License Office 365 Enterprise E1",
"SG_License Office 365 Enterprise E3"
)
$Credentials = Import-Clixml -Path 'C:\PowerShell\Credentials.cred'
$Schedule = New-UDEndpointSchedule -Every 2 -Minute
$Groups = New-UDEndpoint -Schedule $Schedule -Endpoint {
$Cache:Groups = Get-ADGroup -Filter * -SearchBase "OU=Azure License Management,OU=Security Groups,OU=MyCompany,DC=mycompany,DC=co,DC=uk" -Properties * | Where-Object { $RequiredGroups -contains $_.Name } |Sort-Object Name
}
$AZPurchasedCount = New-UDEndpoint -Schedule $Schedule -Endpoint {
Connect-AzureAD -Credential $Credentials.EXOCred
$Cache:AZPurchasedCount = (Get-AzureADSubscribedSku | Where-Object { $_.SkuPartNumber -eq $Group.info }).PrepaidUnits.Enabled
Disconnect-AzureAD
}
$AZConsumedCount = New-UDEndpoint -Schedule $Schedule -Endpoint {
Connect-AzureAD -Credential $Credentials.EXOCred
$Cache:AZConsumedCount = (Get-AzureADSubscribedSku | Where-Object { $_.SkuPartNumber -eq $Group.info }).ConsumedUnits
Disconnect-AzureAD
}
$LicencePage = New-UDPage -Name "Azure Licencing" -DefaultHomePage -AutoRefresh -RefreshInterval 600 -Content {
foreach($Group in $Cache:Groups) {
if($null -eq $AADConnection.Account) {
$AADConnection = Connect-AzureAD -Credential $Credentials.EXOCred
}
$Remaining = $Cache:AZPurchasedCount - $Cache:AZConsumedCount
New-UDRow -Columns {
New-UDColumn -Size 4 {
New-UDCounter -Title $Group.Name -Endpoint {
$Cache:AZPurchasedCount
}
}
New-UDColumn -Size 2 {
New-UDCounter -Title "AD Assigned" -Endpoint {
$Group.Members.Count
}
}
New-UDColumn -Size 2 {
New-UDCounter -Title "Direct Assigned" -Endpoint {
$Cache:AZConsumedCount - $ADCount
}
}
New-UDColumn -Size 2 {
New-UDCounter -Title "Consumed" -Endpoint {
$Cache:AZConsumedCount
}
}
New-UDColumn -Size 2 {
if($Remaining -le 1) {
New-UDCounter -Title "Remaining" -BackgroundColor Red -FontColor White -Endpoint {
$Remaining
}
} elseif($Remaining -le 3) {
New-UDCounter -Title "Remaining" -BackgroundColor Orange -FontColor White -Endpoint {
$Remaining
}
} else {
New-UDCounter -Title "Remaining" -BackgroundColor Green -FontColor White -Endpoint {
$Remaining
}
}
}
}
}
}
$Dashboard = New-UDDashboard -Title "Azure Licencing" -Pages @($LicencePage) -Theme $Theme
Start-UDDashboard -Name "Azure Licencing" -Dashboard $Dashboard -Port 10002 -Endpoint @($Groups, $AZPurchasedCount, $AZConsumedCount) -AutoReload