Hello all,<\/p>\n
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.<\/p>\n
$ScriptPath = ($myinvocation.mycommand.Path).Replace($myinvocation.mycommand.Name,\"\")\n$key = $(Get-Date -format \"MMddhhmmss\")\n\n#It creates a report file in current script position\nNew-Item \"$ScriptPath\\query_vshield_report_$key.html\" -ItemType file | Out-Null\n\n$HTML=@\"\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<style> BODY{font-family:Verdana; background-color:lightblue;}\n\tTABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;} \n\tTH{font-size:1.2em; border-width: 2px;padding: 2px;border-style: solid;border-color: black;background-color:lightskyblue} \n\tTD{border-width: 2px;padding: 2px;border-style: solid;border-color: black;align=right}\n\t</style>\n</head><body>\n<H1>vShield Driver Report</H1>\n<table>\n<colgroup>\n<col/>\n<col/>\n</colgroup>\n<tr bgcolor=yellow><th>Computer Name</th><th>Service Name</th><th>State</th><th>Status</th><th>Started</th></tr>\n\"@\nAdd-Content -Value $HTML -path \"$ScriptPath\\query_vshield_report_$key.html\"\n \n$Servers = Get-Content C:\\temp\\computers.txt\n\nforeach($Server in $Servers)\n{\n\t#Connecting test\n\t$PingResult = Test-Connection -ComputerName $Server -Count 1 -Quiet\n\tif($PingResult)\n\t{\n\t\t#Use the Windows PowerShell to monitor for errors.\n\t\ttry\n\t\t{\t\n\t\t\t<#If the computer we are querying is a DHCP client and the DNS servers setting were \n\t\t\tassigned by a DHCP server option, then do not modify.#>\n\t\t\t$NICs = Get-WmiObject -Class Win32_SystemDriver -Filter \"name='vsepflt'\" -ComputerName $Server -ErrorAction Stop\n\t \n\t\t\tforeach($NIC in $NICs) \n\t\t\t{\t\n\n $qName = $NIC.Name\n $qState = $NIC.State\n $qStatus = $NIC.Status\n\t\t\t$qStarted = $NIC.Started\n\t\t\t\n\t\t\tWrite-Host \"$Server query succeed!\" -ForegroundColor Green\n\t\t\tAdd-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\"\n }\n\n\t\t }\n\t\t#When an error occurs within the Try block, triggers an exception.\n\t\tcatch\n\t\t {\n\t\t\t Write-Warning \"$Server query FAILED! $Error[0]\"\n\t\t\t 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\"\n\t\t }\n\t }\n\t else\n\t {\n\t\t Write-Host \"$Server failed to connect!\" -ForegroundColor Yellow\n\t\t 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\"\n\t }\n\n} \n\n#Modify configure report\nAdd-Content -Value '</table>' -Path \"$ScriptPath\\query_vshield_report_$key.html\"\nAdd-Content -Value '</body></html>' -Path \"$ScriptPath\\query_vshield_report_$key.html\"\nAdd-Content -Value \"<p>---------- $(get-date) ----------</p>\" -Path \"$ScriptPath\\query_vshield_report_$key.html\"\n<\/code><\/pre>","upvoteCount":2,"answerCount":3,"datePublished":"2016-06-08T14:48:54.000Z","author":{"@type":"Person","name":"criscoleet","url":"https://community.spiceworks.com/u/criscoleet"},"acceptedAnswer":{"@type":"Answer","text":"
Advertisement
Think i figured it out.<\/p>\n
Appended the following code after else<\/p>\n
if(-Not $NICs) {\n Write-Host \"$Server Not Installed\"\n 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\"\n } \n<\/code><\/pre>","upvoteCount":0,"datePublished":"2016-06-08T15:13:28.000Z","url":"https://community.spiceworks.com/t/powershell-query-win32_systemdriver-not-installed/502367/3","author":{"@type":"Person","name":"criscoleet","url":"https://community.spiceworks.com/u/criscoleet"}},"suggestedAnswer":[{"@type":"Answer","text":"Hello all,<\/p>\n
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.<\/p>\n
$ScriptPath = ($myinvocation.mycommand.Path).Replace($myinvocation.mycommand.Name,\"\")\n$key = $(Get-Date -format \"MMddhhmmss\")\n\n#It creates a report file in current script position\nNew-Item \"$ScriptPath\\query_vshield_report_$key.html\" -ItemType file | Out-Null\n\n$HTML=@\"\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<style> BODY{font-family:Verdana; background-color:lightblue;}\n\tTABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;} \n\tTH{font-size:1.2em; border-width: 2px;padding: 2px;border-style: solid;border-color: black;background-color:lightskyblue} \n\tTD{border-width: 2px;padding: 2px;border-style: solid;border-color: black;align=right}\n\t</style>\n</head><body>\n<H1>vShield Driver Report</H1>\n<table>\n<colgroup>\n<col/>\n<col/>\n</colgroup>\n<tr bgcolor=yellow><th>Computer Name</th><th>Service Name</th><th>State</th><th>Status</th><th>Started</th></tr>\n\"@\nAdd-Content -Value $HTML -path \"$ScriptPath\\query_vshield_report_$key.html\"\n \n$Servers = Get-Content C:\\temp\\computers.txt\n\nforeach($Server in $Servers)\n{\n\t#Connecting test\n\t$PingResult = Test-Connection -ComputerName $Server -Count 1 -Quiet\n\tif($PingResult)\n\t{\n\t\t#Use the Windows PowerShell to monitor for errors.\n\t\ttry\n\t\t{\t\n\t\t\t<#If the computer we are querying is a DHCP client and the DNS servers setting were \n\t\t\tassigned by a DHCP server option, then do not modify.#>\n\t\t\t$NICs = Get-WmiObject -Class Win32_SystemDriver -Filter \"name='vsepflt'\" -ComputerName $Server -ErrorAction Stop\n\t \n\t\t\tforeach($NIC in $NICs) \n\t\t\t{\t\n\n $qName = $NIC.Name\n $qState = $NIC.State\n $qStatus = $NIC.Status\n\t\t\t$qStarted = $NIC.Started\n\t\t\t\n\t\t\tWrite-Host \"$Server query succeed!\" -ForegroundColor Green\n\t\t\tAdd-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\"\n }\n\n\t\t }\n\t\t#When an error occurs within the Try block, triggers an exception.\n\t\tcatch\n\t\t {\n\t\t\t Write-Warning \"$Server query FAILED! $Error[0]\"\n\t\t\t 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\"\n\t\t }\n\t }\n\t else\n\t {\n\t\t Write-Host \"$Server failed to connect!\" -ForegroundColor Yellow\n\t\t 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\"\n\t }\n\n} \n\n#Modify configure report\nAdd-Content -Value '</table>' -Path \"$ScriptPath\\query_vshield_report_$key.html\"\nAdd-Content -Value '</body></html>' -Path \"$ScriptPath\\query_vshield_report_$key.html\"\nAdd-Content -Value \"<p>---------- $(get-date) ----------</p>\" -Path \"$ScriptPath\\query_vshield_report_$key.html\"\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2016-06-08T14:48:55.000Z","url":"https://community.spiceworks.com/t/powershell-query-win32_systemdriver-not-installed/502367/1","author":{"@type":"Person","name":"criscoleet","url":"https://community.spiceworks.com/u/criscoleet"}},{"@type":"Answer","text":"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.”<\/p>\n
PS C:\\Users\\user\\Desktop> Get-WmiObject -Class Win32_SystemDriver -Filter \"name='vsepflt'\" -ComputerName wpvl1ctx10\n\nDisplayName : VFileFilter\nName : vsepflt\nState : Running\nStatus : OK\nStarted : True\n\nPS C:\\Users\\user\\Desktop> Get-WmiObject -Class Win32_SystemDriver -Filter \"name='vsepflt'\" -ComputerName wpvl1app04\n\nPS C:\\Users\\user\\Desktop> \n<\/code><\/pre>","upvoteCount":0,"datePublished":"2016-06-08T14:55:15.000Z","url":"https://community.spiceworks.com/t/powershell-query-win32_systemdriver-not-installed/502367/2","author":{"@type":"Person","name":"criscoleet","url":"https://community.spiceworks.com/u/criscoleet"}}]}}