You are running it in NSH Script as Type1 or Type2?
If it is Type1: nexec -e serves your requirement here.
nexec -e 'sc query <service name>'
If it is Type2: use for loop
for SERVER in $SERVERS_LIST
nexec $SERVER "sc query <service name>"
Thanks Santhosh for the reply!!
Script is type 1 : Using nexec -e how will it use the server name passed as a parameter
You don't need any parameter if it is Type1. The script/command is anyway going to run on the target directly.
Usage: nexec [-i] hostname cmd ...
nexec [-i] -e cmd ...
-e cmd command and args to execute on current remote host
-nohup Ignore SIGHUP for command and its child process
-ncq Preserve double quotes in command string
If not, you may use the $NSH_RUNCMD_HOST parameter too.