Goodnight,
This is my first post in this forum (Greetings to all :-))
I am a beginner with universal dashboard community and I am stuck with the following code.
What I want to do is define a variable of type $ Cache: var and use it as a parameter so that its value is modified within a function, but I don’t get it.
I leave the code in case you can help me in this.
What happens is that the variable Cache: state_srv retains the original value of false when it is declared and I want its value to be modified when I pass it as a parameter.
Thank you
import-module -Name UniversalDashboard.Community
function Check_ping($srv)
{
#....
#....
# We suppose the function retunr $true
return $true
}
function check_srv
{
Param
(
[Parameter(Mandatory=$true, Position = 0)]
$servidor,
[Parameter(Mandatory=$true, Position = 1)]
[ref][switch]$esta
)
$esta.value = Check_ping ($servidor)
}
$Cache:estado_srv = $false
$Schedule = New-UDEndpointSchedule -Every 30 -Second
$Every30sec = New-UDEndpoint -Schedule $Schedule -Endpoint {
check_srv ("server1") ([ref]$Cache:estado_srv)
}
Start-UdDashboard -Content {
New-UDDashboard -Title "Test" -Content {
New-UDRow -Endpoint {
# Here, $Cache:estado_srv has $false value... Wait?
New-UDCard -Title "Estado" -Text "Global:estado_srv: $Cache:estado_srv"
} -AutoRefresh -RefreshInterval 10
}
} -Endpoint $Every30sec -Port 10001 -AutoReload