Run Pwershell

  • Hi Experts,

    We have a powershell which we need to run from one of our SQL Servers. The script checks for a particular service in 4 servers and if it is stopped ,will start the same.

    How can i achieve this?

  • VastSQL (2/10/2016)


    Hi Experts,

    We have a powershell which we need to run from one of our SQL Servers. The script checks for a particular service in 4 servers and if it is stopped ,will start the same.

    How can i achieve this?

    Are you asking how to run a PS script from a SQL Agent job? Or something else?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (2/10/2016)


    VastSQL (2/10/2016)


    Hi Experts,

    We have a powershell which we need to run from one of our SQL Servers. The script checks for a particular service in 4 servers and if it is stopped ,will start the same.

    How can i achieve this?

    Are you asking how to run a PS script from a SQL Agent job? Or something else?

    Thanks Phil,

    Yes, but the job has to run as a different user .

  • I have some powershell scripts running which is used in a stored procedure.

    This one is giving me all system configurations for the SQL Server

    DECLARE @sql nvarchar(400)

    set @sql = 'powershell.exe -c "Get-WmiObject -Class Win32_ComputerSystem"'

    CREATE TABLE ##output

    (line varchar(255))

    insert ##output

    EXEC xp_cmdshell @sql

    SELECT * FROM ##output

    WHERE line LIKE 'TotalPhysical%'

    DROP TABLE ##output

  • What if the sql service on the server that's running the agent job stops? 😀

    You should create a windows account, to use as a proxy, then on the job step you can use the run as drop down.

    http://msdn.microsoft.com/en-us/library/ms189064.aspx

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply