Hello:
I have problem with passing variable from main file to Page file.
Under main file I have some endpoint that should be refreshed.
Under Page I want to use above endpoint but it looks like that variable $Cache:Data_CountLogons_Input is empty.
Everything works fine under Powershell, but under IIS - it doesn’t work.
- Dashboard file
#Generate pages from files
$PagesPath = Join-Path $PSScriptRoot “Pages”
$Footer = . (Join-Path $PagesPath “footer.ps1”)$Pages = @()
$Pages += . (Join-Path $PagesPath “home.ps1”)Get-ChildItem -Path $PagesPath -Exclude “home.ps1”, “footer.ps1” | ForEach-Object {
$Pages += . $_.FullName
}#Refresh data
#Schedule
$Schedule = New-UDEndpointSchedule -Every 60 -Second#Endpoint
$Endpoint = New-UDEndpoint -Schedule $Schedule -Endpoint {
$Query =
@"
SELECT HostName, COUNT(*) AS Logons FROM [RSDSCReporting].[dbo].[RDPLogons] WHERE (LogonDate >= DATEADD(day,-7, GETDATE())) GROUP BY HostName
"@
$Cache:Data_CountLogons_Input = Get-ODBCData -Query $Query -ConnectionString $env:DSC_CONNECTIONSTRING
}Initialize the Dashboard
$Theme = Get-UDTheme “Default”
$Initialization = New-UDEndpointInitialization -Module ‘DscDashboard’ -Variable ‘$Cache:Data_CountLogons_Input’Start-UDDashboard -Endpoint $Endpoint -Dashboard (
New-UDDashboard -Theme $Theme -Title "Reform School DSC Dashboard" -Pages $Pages -EndpointInitialization $Initialization -Footer $Footer -NavbarLinks $NavBarLinks
) -AutoReload -Port 4242 -Wait #Wait is needed for hosting
- One of Page file
#Create Object
$Cache:Data_CountLogons = New-Object System.Collections.Generic.List[System.Object]#Testing
Set-Content -Path c:\data.txt -Value $Cache:Data_CountLogons_Input#Pass data from SQL to object
$Cache:Data_CountLogons_Input |ForEach-Object {
$Data_Object = New-Object PSObject $Data_Object = [PSCustomObject]@{ Hostname = $_.Hostname Logons = $_.Logons } $Cache:Data_CountLogons.Add($Data_Object)
}
#Testing
Set-Content -Path c:\data2.txt -Value $Cache:Data_CountLogonsNew-UDPage -Name “Logins Counter” -Icon bar_chart -Content {
New-UDCard -Content { New-UDGrid -Title "Count of last 7 days RDP Logins for given server" -Headers @( "Hostname", "Logons" ) -Properties @( "Hostname", "Logons" ) -Endpoint { #Import-Module 'UniversalDashboard.Community' -MinimumVersion 2.0.1 -ErrorAction 'Stop' -Force #Import-Module 'DscDashboard' -Force $Cache:Data_CountLogons | Out-UDGridData } -PageSize 25 -DefaultSortColumn StartTime -DefaultSortDescending -DateTimeFormat "LLLLL" -AutoRefresh -RefreshInterval (10*60) #-ServerSideProcessing } # Card
} # Page
#>