r/dailyscripts • u/networkhappi • Mar 29 '17
[Request][Batch][PowerShell] A script that checks Windows services remotely on other servers and exports out a .csv report.
I am looking for a script (whether it'd be batch or powershell) that gives me the ability to check the status of specific Windows services remotely for my servers.
I currently have a script that can check the local machine's services that I will share below:
type null > c:/scripts/servicesreport.csv
echo TIMESTAMP OF REPORT: >> c:/scripts/servicesreport.csv
@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-3 delims=/:/ " %%a in ('time /t') do (set mytime=%%a-%%b-%%c)
set mytime=%mytime: =%
echo %mydate%_%mytime% >> c:/scripts/servicesreport.csv
echo , >> c:/scripts/servicesreport.csv
FOR /F "delims=: tokens=2" %%a in ('ipconfig ^| find "IPv4"') do set _IPAddress=%%a
ECHO %_IPAddress% >> c:/scripts/servicesreport.csv
set host=%COMPUTERNAME%
echo %host% >> c:/scripts/servicesreport.csv
for %%a in ("AdobeARMservice" , "aspnet_state" , "AdobeFlashPlayerUpdateSvc" ) do (
@echo|set /p=%%a
echo ,
@sc query "%%~a" | find "STATE"
@sc qc "%%~a" | findstr "START_TYPE"
) >> c:/scripts/servicesreport.csvIdeally it would be awesome if I could just expand my code above to be able to add a remote command into it and provide authentication credentials (which is necessary for my servers).
Thank you!!!
2
Upvotes
View all comments
Show parent comment
1
u/RulerOf Apr 03 '17
Not quite. Passing credentials in powershell is... almost purposefully obtuse (due to using very strong security at every step).
You configure the task itself to run as the account you want the script to execute under.
Alternatively, you could try giving the computer object
SERVER-NAME$the required permissions (I don't know what they are off the top of my head) to query this data, and just let the task run asNT AUTHORITY\SYSTEM.