Listview check Service status and change icon
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Listview check Service status and change icon
Get-ADComputer -Filter * -SearchBase 'OU=DOMUSERS,DC=DOM,DC=LOCAL' |
ForEach-Object {
$item1 = New-Object System.Windows.Forms.ListViewItem
$item1.Text = $_.Name
$item1.Name = $_.Name
$item1.SubItems.Add('')
$item1.SubItems.Add('')
$listview2.Items.Add($item1)
if(Test-Connection -ComputerName $_.dnshostname -Count 1 -Quiet){
$item1.ImageIndex = 0
$item1.SubItems[1].Text = 'Online'
$item1.SubItems[1].ForeColor = 'Green'
$ProtectionStatus = Invoke-Command -ScriptBlock { (Get-BitLockerVolume).ProtectionStatus } -ComputerName $_.name -Credential $Global:DomainCredentials
if ($ProtectionStatus -match 'On') {
$item1.SubItems[2].Text = 'On'
$item1.UseItemStyleForSubItems = $true;
$item1.SubItems[2].ForeColor = 'Green'
}else{
$item1.SubItems[2].Text = 'Off'
$item1.UseItemStyleForSubItems = $false;
$item1.SubItems[2].ForeColor = 'DarkRed'
}
}else{
$item1.ImageIndex = 1
$item1.SubItems[1].Text = 'Offline'
$item1.SubItems[1].ForeColor = 'Red'
}
}
#>
ForEach-Object {
$item1 = New-Object System.Windows.Forms.ListViewItem
$item1.Text = $_.Name
$item1.Name = $_.Name
$item1.SubItems.Add('')
$item1.SubItems.Add('')
$listview2.Items.Add($item1)
if(Test-Connection -ComputerName $_.dnshostname -Count 1 -Quiet){
$item1.ImageIndex = 0
$item1.SubItems[1].Text = 'Online'
$item1.SubItems[1].ForeColor = 'Green'
$ProtectionStatus = Invoke-Command -ScriptBlock { (Get-BitLockerVolume).ProtectionStatus } -ComputerName $_.name -Credential $Global:DomainCredentials
if ($ProtectionStatus -match 'On') {
$item1.SubItems[2].Text = 'On'
$item1.UseItemStyleForSubItems = $true;
$item1.SubItems[2].ForeColor = 'Green'
}else{
$item1.SubItems[2].Text = 'Off'
$item1.UseItemStyleForSubItems = $false;
$item1.SubItems[2].ForeColor = 'DarkRed'
}
}else{
$item1.ImageIndex = 1
$item1.SubItems[1].Text = 'Offline'
$item1.SubItems[1].ForeColor = 'Red'
}
}
#>
Re: Listview check Service status and change icon
is it possible center Status and Bitlocker values text ?
Re: Listview check Service status and change icon
This is the one that works the way you want:
- Get-ADComputer -Filter * -SearchBase 'OU=DOMUSERS,DC=DOM,DC=LOCAL' |
- ForEach-Object {
- $item1 = New-Object System.Windows.Forms.ListViewItem
- $item1.Text = $_.Name
- $item1.Name = $_.Name
- $item1.SubItems.Add('')
- $item1.SubItems.Add('')
- $listview2.Items.Add($item1)
- $item1.UseItemStyleForSubItems = $false
- if (Test-Connection -ComputerName $_.dnshostname -Count 1 -Quiet) {
- $item1.ImageIndex = 0
- $item1.ForeColor = 'Green'
- $item1.SubItems[1].Text = 'Online'
- $item1.SubItems[1].ForeColor = 'Green'
- $ProtectionStatus = Invoke-Command -ScriptBlock { (Get-BitLockerVolume).ProtectionStatus } -ComputerName $_.name -Credential $Global:DomainCredentials
- if ($ProtectionStatus -match 'On') {
- $item1.SubItems[2].Text = 'On'
- $item1.SubItems[2].ForeColor = 'Green'
- } else {
- $item1.SubItems[2].Text = 'Off'
- $item1.SubItems[2].ForeColor = 'DarkRed'
- }
- } else {
- $item1.ImageIndex = 1
- $item1.SubItems[1].Text = 'Offline'
- $item1.SubItems[1].ForeColor = 'Red'
- }
- }
Re: Listview check Service status and change icon
Here is a much easier way to generate columns.
- $ix = $listview2.Columns.Add((New-Object System.Windows.Forms.ColumnHeader))
- $listview2.Columns[$ix].name = 'Hostname'
- $listview2.Columns[$ix].Text = 'Hostname'
- $listview2.Columns[$ix].Width = 150
- $ix = $listview2.Columns.Add((New-Object System.Windows.Forms.ColumnHeader))
- $listview2.Columns[$ix].name = 'Status'
- $listview2.Columns[$ix].Text = 'Status'
- $listview2.Columns[$ix].Width = 60
- $ix = $listview2.Columns.Add((New-Object System.Windows.Forms.ColumnHeader))
- $listview2.Columns[$ix].name = 'Bitlocker'
- $listview2.Columns[$ix].Text = 'Bitlocker'
- $listview2.Columns[$ix].Width = 60
Re: Listview check Service status and change icon
Consider this:
$ix = $listview2.Columns.Add((New-Object System.Windows.Forms.ColumnHeader))
$listview2.Columns[$ix].name = 'Hostname'
$listview2.Columns[$ix].Text = 'Hostname'
$listview2.Columns[$ix].Width = 150
$listview2.Columns[$ix].TextAlign = 'Center'
"AutoComplete" in PowerShell will help you find all properties.
$ix = $listview2.Columns.Add((New-Object System.Windows.Forms.ColumnHeader))
$listview2.Columns[$ix].name = 'Hostname'
$listview2.Columns[$ix].Text = 'Hostname'
$listview2.Columns[$ix].Width = 150
$listview2.Columns[$ix].TextAlign = 'Center'
"AutoComplete" in PowerShell will help you find all properties.
Re: Listview check Service status and change icon
Great !!!
it works perfectly !!!
Many many thanks !!!
it works perfectly !!!
Many many thanks !!!
Re: Listview check Service status and change icon
Is it possible to add the icon in the second or third column ?