How to make a wait between powershell command

Hello, it’s my first question here and i’m hope isn’t a stupid question.
So I’have an error message when i’m execute many powershell command in UD.

Exemple, if I load a page with:

`New-UDLayout -Columns 5 -Content {

    ############### Total User AD

    New-UDCounter -BackgroundColor "#1D7FD6" -Title "Total User AD" -Icon user -Endpoint {
		(Get-ADUser -filter *).count | ConvertTo-Json

    ############### Total User AD enabled

    New-UDCounter -BackgroundColor "#1DA9D6" -Title "Total User AD enabled" -Icon user -Endpoint {
		(Get-AdUser -filter * |Where {$_.enabled -eq "True"}).count | ConvertTo-Json

    ############### Total User AD disabled

    New-UDCounter -BackgroundColor grey -Title "Total User AD disabled" -Icon user -Endpoint {
		(Get-AdUser -filter * |Where {$_.enabled -ne "True"}).count | ConvertTo-Json

    ############### Total User AD whit Password never expires

    Sleep 10
    New-UDCounter -BackgroundColor "#1DD6A4" -Title "Password never expires" -Icon user -Endpoint {
        $selection = "EmployeeID", "Name", "SamAccountName","ObjectSid","ObjectGUID","Enabled", 
        "UserPrincipalName", "whenChanged", "whenCreated", "PasswordNeverExpires", "PasswordLastSet",
         "LastLogonDate", "lastLogonTimestamp", "DistinguishedName", "Description"
         $resultPwdneverExp = Search-ADAccount -UsersOnly -PasswordNeverExpires
         $psne = $resultPwdneverExp | Get-ADUser -Properties * | select $selection 
         $psne.Count | ConvertTo-Json

i’m get this:

translate : “A connection to the directory on which the request is being processed was not available. This is probably a transitional situation.”

I thinks there are too many questions/commands of my active directory.

My question is: Is it possible to add a wait between powershell command or between grid for give time to my AD to reply correctly?


Welcome to UD forums!

Using Where {$_.enabled -ne "True"}).count isn’t too good. As it then has to grab all accounts, and then check each of them if they are enabled/disabled.

If you instead use the filter, only the data you want is returned, and is much faster.


get-aduser -filter ‘Enabled -eq $false’


get-aduser -filter ‘Enabled -eq $true’

Something like that goes for the Password never expires one. While not critical, using -properties

I’d suggest using a scheduled endpoint to collect the data and then just display the session data on the dashboard:

That way you can control how often AD is queried.


Thank you gentlemen for your solutions.

I solved my dashboard with your help.

$Dashboard = New-UDDashboard -Theme $theme -Title "AD Dashbord" -Pages @($Page1)

New-UDHeading -Size 3 -Content { New-UDCard -BackgroundColor "#1D7FD6" -Content { "AD USERS INFORMATIONS" }}

$Schedule = New-UDEndpointSchedule -Every 1 -Hour

$ADUsertotal = New-UDEndpoint -Schedule $Schedule -Endpoint {
    $Cache:ADUsertotal = (Get-ADUser -filter *).count | ConvertTo-Json
$ADUserenabled = New-UDEndpoint -Schedule $Schedule -Endpoint {
    $Cache:ADUserenabled = (Get-ADUser -filter {Enabled -eq $true}).count | ConvertTo-Json
$ADUserdisabled = New-UDEndpoint -Schedule $Schedule -Endpoint {
    $Cache:ADUserdisabled = (Get-ADUser -filter {Enabled -eq $false}).count | ConvertTo-Json
$ADPasswordNeverExpires = New-UDEndpoint -Schedule $Schedule -Endpoint {
    $Cache:ADPasswordNeverExpires = (Get-ADUser -filter {PasswordNeverExpires -eq $true}).count | ConvertTo-Json

New-UDLayout -Columns 4 -Content {
New-UDCounter -BackgroundColor "#1D7FD6" -Title "Total User AD" -Icon user -Endpoint {
		    } -AutoRefresh -RefreshInterval 1

    New-UDCounter -BackgroundColor "#1DA9D6" -Title "Total User AD enabled" -Icon user -Endpoint {
	    } -AutoRefresh -RefreshInterval 1

    New-UDCounter -BackgroundColor grey -Title "Total User AD disabled" -Icon user -Endpoint {
	    } -AutoRefresh -RefreshInterval 1

    New-UDCounter -BackgroundColor "#1DD6A4" -Title "Password never expires" -Icon user -Endpoint {
    } -AutoRefresh -RefreshInterval 1

1 Like

Another thing I do not understand.

Why when I run my server with
Start-UDDashboard -Port 10009 -Dashboard $Dashboard -name "AD_DashBoard" -Endpoint $ADUsertotal
it works.

But when I launch
Start-UDDashboard -Port 10009 -Dashboard $Dashboard -name "AD_DashBoard" -Endpoint @( $ADUsertotal, $ADUserenabled, $ADUserdisabled, $ADPasswordNeverExpires )
it does not work and shows that

Start-UDDashboard : Impossible de lier le paramètre « Endpoint ». Impossible de convertir la valeur « [ » du type « System.String » en type « UniversalDashboard.Models.Endpoint ».
Au caractère Ligne:1 : 84

  • … " -Endpoint [$ADUsertotal,$ADUserenabled,$ADUserdisabled,$ADPasswordN …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidArgument : (:') [Start-UDDashboard], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,UniversalDashboard.Cmdlets.StartDashboardCommand

Do you have an idea?

Hi @Fitz22

Bit of a language barrier here.
It seems like you’re trying to pass a string value into the endpoint init.

Could you share more some code? Or could you try eliminating the endpoints and see which one fails?

The full code is above.
I removed one by one each endpoint.
If i use just one endpoint like “-endpoint $endpoint1” it’s right.
But if i use @($endpoint1 , $endpoint2 , $endpoint3…).

Hi again @Fitz22,

Cannot replicate the issue with the following code:

Can you share your complete dashboard.ps1?

My bad


Define the endpoints outside the -content scriptblock and you should be good 2 go :slight_smile:

1 Like

You are a genius.
It’s functional.
Realy thank you.

1 Like