Link to home
Start Free TrialLog in
Avatar of sweetaz
sweetaz

asked on

How to run a SQL query for all machines in an OU

I have a SQL query that I need to run on all machines in an OU in a W2k3 Server Windows XP environment.
The .bat is located in the netlogon share of the DC and is as follows:

***********
cd\
cd Program Files\Microsoft SQL Server\80\Tools\Binn                  
OSQL -S (local) -d BOData -E -i \\dc\netlogon\query1.sql
REM KEY-S [server] -d [database] -E [trusted connection] -I [input file]
                  
OSQL -S (local) -d POSLocal -E -i \\dc\netlogon\query1.sql
REM KEY-S [server] -d [database] -E [trusted connection] -I [input file]

exit
************

I want to run this without user input and users do not have admin privelges. Can anyone explain to me a way to achieve this?

Regards
SweetAz
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

The problem might not be that they don't have admin privilages....it might just be that your calling the *.sql file from a unc path.  Try copying the .sql file to the local machine first.  Also, test it using a regular batch file logged in as a regular user, and add a pause at the  end to see what errors are output in ms-dos.  Also you don't need to put exit at the end.

cd\
xcopy "\\dc\netlogon\query1.sql" "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn" /D /I /Y
cd "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn"
OSQL -S (local) -d BOData -E -i query1.sql
REM KEY-S [server] -d [database] -E [trusted connection] -I [input file]
                 
OSQL -S (local) -d POSLocal -E -i query1.sql
REM KEY-S [server] -d [database] -E [trusted connection] -I [input file]
ASKER CERTIFIED SOLUTION
Avatar of younghv
younghv
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sweetaz
sweetaz

ASKER

Thanks Younghv I have pstools installed but didnt think to use psexec.
Cheers
Sweetaz
Hoo Ahh!
Thank you for the points.

Sysinternals stuff is so good, I would pay for it (but don't tell Bill Gates).

Vic