Sunday, 15 February 2015

powershell - file location different on computers and space issues -



powershell - file location different on computers and space issues -

i have below code , checks computer version info , service status.

the problem have servers have located .exe in different places:

c:\program files\snare\snarecore.exe c:\program files (x86)\snare\snarecore.exe d:\apps\snare\snarecore.exe

how script below run right version? think can utilize path service checking? doing remotly , have rights server , works fine - having possiblt create 3 (or more!) scripts based on 3 locations of executable is!

also, ones have space in name (../program file..) set quotes powershell can read whole line , not error out due space in name?

code:

clear $erroractionpreference = "silentlycontinue" $logfile = "c:\temp\output_cdrive.log" function logwrite { param([string]$logstring) add-content $logfile -value $logstring } $computer = get-content -path c:\temp\servers2.txt foreach ($computer1 in $computer){ $service = get-wmiobject win32_service -filter "name = 'snare'" -computername $computer1 if (test-connection $computer1 -quiet) { $version = (get-command ""\\$computer1\c$\program files (x86)\snare\snarecore.exe"").fileversioninfo.fileversion if($service.state -eq 'running') { logwrite "$computer1 started $version" } else { logwrite "$computer1 stopped $version" } } else { logwrite "$computer1 down" -foregroundcolor reddish } }

thanks,

you can check pathname property of service exe location :

ps>(get-wmiobject win32_service -filter "name='spooler'").pathname c:\windows\system32\spoolsv.exe

powershell powershell-v2.0

No comments:

Post a Comment