Hello all,

So I am having a bit of trouble with a script I am using to query vShield system driver. Specifically when I run this script it doesn’t appear to log servers that do not have the service installed. Pretty sure its something to do with the query itself or the Write-Warning. Any help greatly appreciated.

$ScriptPath = ($myinvocation.mycommand.Path).Replace($myinvocation.mycommand.Name,"")
$key = $(Get-Date -format "MMddhhmmss")

#It creates a report file in current script position
New-Item "$ScriptPath\query_vshield_report_$key.html" -ItemType file | Out-Null

$HTML=@"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style> BODY{font-family:Verdana; background-color:lightblue;}
	TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;} 
	TH{font-size:1.2em; border-width: 2px;padding: 2px;border-style: solid;border-color: black;background-color:lightskyblue} 
	TD{border-width: 2px;padding: 2px;border-style: solid;border-color: black;align=right}
	</style>
</head><body>
<H1>vShield Driver Report</H1>
<table>
<colgroup>
<col/>
<col/>
</colgroup>
<tr bgcolor=yellow><th>Computer Name</th><th>Service Name</th><th>State</th><th>Status</th><th>Started</th></tr>
"@
Add-Content -Value $HTML -path "$ScriptPath\query_vshield_report_$key.html"
 
$Servers = Get-Content C:\temp\computers.txt

foreach($Server in $Servers)
{
	#Connecting test
	$PingResult = Test-Connection -ComputerName $Server -Count 1 -Quiet
	if($PingResult)
	{
		#Use the Windows PowerShell to monitor for errors.
		try
		{	
			<#If the computer we are querying is a DHCP client and the DNS servers setting were 
			assigned by a DHCP server option, then do not modify.#>
			$NICs = Get-WmiObject -Class Win32_SystemDriver -Filter "name='vsepflt'" -ComputerName $Server -ErrorAction Stop
	        
			foreach($NIC in $NICs) 
			{	

            $qName = $NIC.Name
            $qState = $NIC.State
            $qStatus = $NIC.Status
			$qStarted = $NIC.Started
			
			Write-Host "$Server query succeed!" -ForegroundColor Green
			Add-Content -Value "<tr bgcolor=#F0F8FF><td align=left>$Server</td><td align=center>$qName</td><td align=center>$qState</td><td align=center>$qStatus</td><td align=center>$qStarted</td></tr>" -Path "$ScriptPath\query_vshield_report_$key.html"
            }

		 }
		#When an error occurs within the Try block, triggers an exception.
		catch
		    {
			    Write-Warning "$Server query FAILED! $Error[0]"
			    Add-Content -Value "<tr bgcolor=#F0F8FF><td align=left>$server</td><td align=center>$error</td><td align=center> </td><td align=center> </td><td align=center> </td></tr>" -Path "$ScriptPath\query_vshield_report_$key.html"
		    }
	    }
	        else
	        {
		        Write-Host "$Server failed to connect!" -ForegroundColor Yellow
		        Add-Content -Value "<tr bgcolor=#F0F8FF><td align=left>$server</td><td align=center>Failed to connect</td><td align=center> </td><td align=center> </td><td align=center> </td></tr>" -Path "$ScriptPath\query_vshield_report_$key.html"
	        }

}    

#Modify configure report
Add-Content -Value '</table>' -Path "$ScriptPath\query_vshield_report_$key.html"
Add-Content -Value '</body></html>' -Path "$ScriptPath\query_vshield_report_$key.html"
Add-Content -Value "<p>---------- $(get-date) ----------</p>" -Path "$ScriptPath\query_vshield_report_$key.html"
2 Spice ups

Based on the PowerShell results using a single workstation. It shows a blank value. Guess i could use a $null type statement to add text “not installed.”

PS C:\Users\user\Desktop> Get-WmiObject -Class Win32_SystemDriver -Filter "name='vsepflt'" -ComputerName wpvl1ctx10

DisplayName : VFileFilter
Name        : vsepflt
State       : Running
Status      : OK
Started     : True

PS C:\Users\user\Desktop> Get-WmiObject -Class Win32_SystemDriver -Filter "name='vsepflt'" -ComputerName wpvl1app04

PS C:\Users\user\Desktop> 

:open_mouth: Think i figured it out.

Appended the following code after else

            if(-Not $NICs) {
                Write-Host "$Server Not Installed"
                Add-Content -Value "<tr bgcolor=#F0F8FF><td align=left>$server</td><td align=center>Not installed</td><td align=center> </td><td align=center> </td><td align=center> </td></tr>" -Path "$ScriptPath\query_vshield_report_$key.html"
            }