So basically, all I want to do is execute an "sc" command on 100 servers whose names are mentioned in a text file "server.txt". I tried the following and it doesnt work as it returns empty notepad file.
for /f %%a in (servers.txt) do sc \\server_name query | find "SERVICE_NAME">>servicecontroller.txt
I tried the above command locally and it worked just fine. I know the issue is in the "\server_name". Not sure what about it is wrong. Do i need to use the hidden shares?
Like this maybe?
\\server_name\c$ /user:domain\username password
Or like this?
\\server_name\c$
解决方案
If you've hardcoded \\server_name there rather than %%a, then that's your problem. Try this instead:
for /f %%a in (servers.txt) do sc \\%a query | find "SERVICE_NAME">>servicescontroller.txt
EDIT :
The following line helps in getting admin access consistently on all the servers. This is the line I(OP) was looking for.
net use \\servername\ipc$ /u:domain\user password