phenry194
Posts: 187
Score: 0 Joined: 3/30/2007 Status: offline
|
I borrowed a script from someone that pings machines, then checks to see if a hot fix is installed, and then it populates an excel spreadsheet with the results. Very cool. I modified it to ping a list of machines and then check to see if a particular executable exists. I have it working except the last part where it populates the excel spreadsheet. I want it to tell it the executable exists or it doesn't. No matter what I do on it, it populates it with results of NO machines having that executable, and I know a number of them do. Can someone please take a look at the bottom half of the script and tell me where I have gone wrong? I'm pretty new to powershell, and very close, but not close enough. Thanks for any help you can provide. I have remmed out a bunch of stuff since this is a borrowed script, but I wanted to preserve it for reference if necessary. Thanks. ## *********** Beginning of function Pingme *********** function PingMe ($pc) { $ping = new-object System.Net.NetworkInformation.Ping $rslt = $ping.send("$pc") if ($rslt.status –eq “Success”) { #write-host write-host (“ping $pc worked”) -foregroundcolor "Yellow" #write-host return $true } else { "" write-warning “$pc is not reachable” return $false } # $ping = $null } # End of function PingMe ############################################################ $ErrorActionPreference = "SilentlyContinue" #$Ppid = "KB932762" # $EXobj = New-Object -comobject Excel.Application $EXobj.visible = $True $book = $EXobj.Workbooks.Add() $col = $book.Worksheets.Item(1) $col.Cells.Item(1,1) = "Machine Name" $col.Cells.Item(1,2) = "IClient.exe" #$col.Cells.Item(1,3) = "InstalledBy" #$col.Cells.Item(1,4) = "InstalledOn" $dd = $col.UsedRange $dd.Interior.ColorIndex = 19 $dd.Font.ColorIndex = 11 $dd.Font.Bold = $True $dd.EntireColumn.AutoFit() $row = 2 foreach ($pc in get-content c:\temp\laptops2.txt) { $online=PingMe($pc) if ($online -eq $true) { function integrity ($pc) { $newpath="\\$pc\c$\program files\checkpoint\integrity client\iclient.exe" get-childitem $newpath} $var = get-content 'c:\temp\laptops2.txt' foreach ($i in $var) {write-host ($i)} $yeppers=integrity if ($yeppers -eq $true) { $col.Cells.Item($row,1) = $pc $col.Cells.item($row,2) = "installed" #$col.Cells.Item($row,3) = $Hotp.InstalledBy #$col.Cells.Item($row,4) = $Hotp.InstalledOn } else { $col.Cells.Item($row,1) = $pc $col.Cells.item($row,2) = "Not installed" #$col.Cells.Item($row,3) = "None" #$col.Cells.Item($row,4) = "None" } #$Hotp="" $row = $row + 1 } }
|