How can I run a powershell script locally?

29 views
Skip to first unread message

Kessy Similien

unread,
Dec 18, 2017, 7:50:14 PM12/18/17
to Ansible Project
I've created a script to install SQL Server silently. I'm using Ansible to push the files to my machine and trying to run the .ps1 script but none of the modules I've tried have successfully called the script. 

Ive tried: ansible machines -m win_psexec -a "command='Powershell c:\temp\sql-setup.ps1'"

It says: 

10.0.0.5 | SUCCESS => {
    "changed": true,
    "delta": "0:00:02.790980",
    "end": "2017-12-19 12:34:07.536547",
    "failed": false,
    "psexec_command": "psexec.exe -accepteula Powershell c:\temp\\sql-setup.ps1",
    "rc": 0,
    "start": "2017-12-19 12:34:04.745567",
    "stderr": "Powershell exited with error code 0.\r\n",
    "stderr_lines": [
        "Powershell exited with error code 0."
    ],
    "stdout": "\r\nPsExec v2.2 - Execute processes remotely\r\nCopyright (C) 2001-2016 Mark Russinovich\r\nSysinternals - www.sysinternals.com\r\n\r\n",
    "stdout_lines": [
        "",
        "PsExec v2.2 - Execute processes remotely",
        "Copyright (C) 2001-2016 Mark Russinovich",
        "Sysinternals - www.sysinternals.com",
        ""
    ]
}

 but nothing happened on the actual machine. 

I tried script / win_command / win_shell 

Is this possible at all? 

Jordan Borean

unread,
Dec 18, 2017, 9:59:18 PM12/18/17
to Ansible Project
It is definitely possible but you will probably be coming up with other errors because you either need to use CredSSP, Kerberos with credential delegation, become, or psexec to install SQL Server.

For the case around running a powershell script I would try the following

- win_command: PowerShell.exe -ExecutionPolicy Bypass -File C:\temp\sql-setup.ps1

This will give you the full output in the stdout and stderr which you can use to help debug what is happening. Unfortunately psexec does not keep track of the stdout/stderr so it is hard to tell what may be happening there.

Thanks

Jordan
Reply all
Reply to author
Forward
0 new messages