Link to home
Start Free TrialLog in
Avatar of Robb Hill
Robb HillFlag for United States of America

asked on

Executing Powershell script from SQL Server

I have an agent job running....that kills a blocking spid on ocasion and when it does this...I have to manually go to my application server and restart an exe....we can call it myprogram.exe for now.  There are usually serveral versions of myprogram.exe running at the same time...all with the same name..just different proc id.

With that being said..is there away to call some powershell or some thing that when i run this agent job..and call this stored proc to manage this...that it an also somehow kick off a script to restart these myprogram.exe?
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Hi Robb,
Pls try like this ..

param
(
	[String]$param1
)
clear; 
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection "server=ServerName,1434;database=YourDBName;user=Pawan;Password=pw"
$SqlConnection.Open()

$sqlCommand=$sqlConnection.CreateCommand()
$sqlCommand.CommandTimeout = 120
$sqlCommand.CommandText=" EXEC yourSPName " + $param1

$sqlReader = $sqlCommand.ExecuteReader()
$SqlConnection.close()

Open in new window


Hope it helps!
Avatar of Robb Hill

ASKER

I think that is the reverse..I need to call powershell from sql server
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India 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
Pawan:

Thank you so much...cant believe that did not just pop on google:)


I will play around with this..thanks again.