|
Can someone tell me, what I'm doing wrong? Have tried changing the variable for $computer name - it does work when an explict computer name is used, But I would like to check 50 plus servers... and not do it manually.
Thanks for your advice!
;--------------------------------------------- code Break=on $LogFile = '090805.log' Call 'C:\KixScripts\UDF\NetView.udf' IF RedirectOutput($LogFile,1) = 0 for each $computer in NetView $xQuery = WMIService("SpntSvc","query","$computer") $xMode = WMIService("SpntSvc","startmode","$computer") $computer + $xQuery + $xMode ? next endif
function WMIService($service,optional $action,optional $startmode,optional $computer) Dim $wmi,$svc,$services,$sm,$st if not $computer $computer=@wksta endif $wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer") $services=$wmi.ExecQuery("Select * from Win32_Service where name = '$service'") if not @error for each $svc in $services If instr("AUTOMATIC,MANUAL,DISABLED",$startmode) $ = $svc.ChangeStartMode($startmode) endif if $svc.State <> $action select case $action = "START" $ = $svc.StartService() case $action = "STOP" $ = $svc.StopService() case $action = "PAUSE" $ = $svc.PauseService() case $action = "RESUME" $ = $svc.ResumeService() endselect endif next $wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer") $services=$wmi.ExecQuery("Select * from Win32_Service where name = '$service'") for each $svc in $services $sm=$svc.StartMode $st=$svc.State $WMIService = "$st $sm" next $wmi=0 else exit 2 endif endfunction
|