Author Posts

August 12, 2016 at 3:01 pm

Hello, I'm new to Sapien and have a question that can probably be answered here...

I have a list box I'm trying to keep updated with our locked out users, I want this listbox to be updated every 5 seconds or so.

They have a prebuilt function for generating the contents of a list box, but i'm not sure where I would stick code to continuously update it...

I have it generate the listbox on load as seen below, but where would i Stick some code to do like a

do 
{
  #$lockedlist is a checkedlistbox form object
  Load-ListBox $LockedList (Search-ADAccount -LockedOut) "name"
  start-sleep 5
}
while (1 -eq 1)

Complete code below..


$form1_Load={
	#TODO: Initialize Form Controls here
	
	Load-ListBox $LockedList (Search-ADAccount -LockedOut) "name"
	
	
}

#region Control Helper Functions
function Load-ListBox 
{

	Param (
		[ValidateNotNull()]
		[Parameter(Mandatory=$true)]
		[System.Windows.Forms.ListBox]$ListBox,
		[ValidateNotNull()]
		[Parameter(Mandatory=$true)]
		$Items,
	    [Parameter(Mandatory=$false)]
		[string]$DisplayMember,
		[switch]$Append
	)
	
	if(-not $Append)
	{
		$listBox.Items.Clear()	
	}
	
	if($Items -is [System.Windows.Forms.ListBox+ObjectCollection] -or $Items -is [System.Collections.ICollection])
	{
		$listBox.Items.AddRange($Items)
	}
	elseif ($Items -is [System.Collections.IEnumerable])
	{
		$listBox.BeginUpdate()
		foreach($obj in $Items)
		{
			$listBox.Items.Add($obj)
		}
		$listBox.EndUpdate()
	}
	else
	{
		$listBox.Items.Add($Items)	
	}

	$listBox.DisplayMember = $DisplayMember	
}
#endregion
  • This topic was modified 2 years, 2 months ago by  ertuu85.

August 12, 2016 at 3:57 pm

Got it by adding a timer to the form

$form1_Load={
	#TODO: Initialize Form Controls here
	
	Load-ListBox $LockedList (Search-ADAccount -LockedOut) "name"
	# timer1
	#
	$timer1.Enabled = $True
	$timer1.Interval = 3000
	$timer1.add_Tick($timer1_Tick)
}

$timer1_Tick={
#TODO: Place custom script here
Load-ListBox $LockedList (Search-ADAccount -LockedOut) "name"
}