# How to run powershell scripts from jenkins

**URL:** <https://community.jenkins.io/t/how-to-run-powershell-scripts-from-jenkins/12517>\
**Category:** Using Jenkins\
**Created:** [February 15, 2024, 8:56pm UTC](https://community.jenkins.io/t/how-to-run-powershell-scripts-from-jenkins/12517 "2024-02-15T20:56:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vcapalore](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/vcapalore/32/6328_2.png) [@vcapalore](https://community.jenkins.io/u/vcapalore)\
**Post date:** [February 15, 2024, 8:56pm UTC](https://community.jenkins.io/t/how-to-run-powershell-scripts-from-jenkins/12517/1 "2024-02-15T20:56:20Z")

</div>

We would like to run pipeline job to call power shell scripts on remote windows hosts, we don’t want to use username/password. I couldn’t get openssh to work, what other options we have for windows authentication.

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [February 17, 2024, 5:52pm UTC](https://community.jenkins.io/t/how-to-run-powershell-scripts-from-jenkins/12517/2 "2024-02-17T17:52:01Z")

</div>

What was going wrong with openssh? It’s definitely the best method. I don’t know of any other auth methods that would work.

---

<div class="post-metadata">

**Author:** ![martens](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@martens](https://community.jenkins.io/u/martens)\
**Post date:** [March 6, 2025, 10:10am UTC](https://community.jenkins.io/t/how-to-run-powershell-scripts-from-jenkins/12517/3 "2025-03-06T10:10:58Z")

</div>

Maybe a bit late, but:

You can use PSExec.exe from [

### PsTools - Sysinternals

]([PsTools - Sysinternals | Microsoft Learn](https://learn.microsoft.com/de-de/sysinternals/downloads/pstools))

```auto
  withCredentials([usernamePassword(credentialsId: CREDENTIALS, passwordVariable: 'CREDS_P', usernameVariable: 'CREDS_U')]) {
   
    // remoteserver: name of the remote server
    // domain: the domain the win-user is running under Jenkins creds don't have that
    // C:\\...\\test.ps1 full path to the script (beforehand, I use "net use" and dir() to copy the ps1-file over/create it) 
    writeFile file: "run.bat", text: "\"${env.WORKSPACE}\\PSTools\\PSExec.exe\" \\\\remoteserver -u domain\\" + CREDS_U + " -p " + CREDS_P + " cmd /c \"powershell C:\\...\\test.ps1\""
    // PSTools are located in the subdir PSTools
    // /accepteula is for agreeing to the eula to make shure it runs
    bat(returnStdout: true, script: ".\\PSTools\\PSExec.exe \\\\localhost -u domain\\%CREDS_U% -p %CREDS_P% /accepteula cmd /c \"${env.WORKSPACE}\\run.bat\"")
    
  }

```
