When I add "-Clear" to Add-ListViewItem and click the button, only 1 record appears in the List View. What do I need to do to clear the List View before populating with new data?
Code: Select all
$button1_Click={
#TODO: Place custom script here
Get-DBlist -DBSearch $global:DBName
}
$textbox1_TextChanged={
#TODO: Place custom script here
$global:DBName = $textbox1.text
}
Function Get-DBList
{
param (
[CmdletBinding()]
[Parameter(Mandatory = $false, Position = 1)]
[String]$DBSearch
)
$server = "sqlserver,1433"
$QueryCMS = "
SELECT
servername
,database_name
FROM Database.Table
WHERE
name like '%$DBSearch%'
and state_desc = 'Online'
and
name not in ('master','model','msdb','tempdb')
order by 1,2
"
Invoke-Sqlcmd -ServerInstance $server -query $QueryCMS |
ForEach-Object{
Add-ListViewItem -ListView $listview1 -Items $_.servername -SubItems $_.database_name -Clear
}
}