Run Pwershell

  • VastSQL

    SSC-Dedicated

    Points: 35906

    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?

  • Phil Parkin

    SSC Guru

    Points: 244739

    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?

    If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.
    See https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help/ for details of how to post T-SQL code-related questions.

  • VastSQL

    SSC-Dedicated

    Points: 35906

    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 .

  • webtomte

    Ten Centuries

    Points: 1125

    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

  • benjamin.reyes

    SSCertifiable

    Points: 5249

    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 5 (of 5 total)

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