# How I can execute Windows Commands on remote server using the Jenkins Declarative Pipeline?

**URL:** <https://community.jenkins.io/t/how-i-can-execute-windows-commands-on-remote-server-using-the-jenkins-declarative-pipeline/879>\
**Category:** Ask a question\
**Created:** [November 25, 2021, 1:29pm UTC](https://community.jenkins.io/t/how-i-can-execute-windows-commands-on-remote-server-using-the-jenkins-declarative-pipeline/879 "2021-11-25T13:29:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cane](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@cane](https://community.jenkins.io/u/cane)\
**Post date:** [November 25, 2021, 1:29pm UTC](https://community.jenkins.io/t/how-i-can-execute-windows-commands-on-remote-server-using-the-jenkins-declarative-pipeline/879/1 "2021-11-25T13:29:14Z")

</div>

Hi,

can someone suggest me a method how I can execute in Jenkins Declarative Pipeline remote windows commands (e.g. using the cmd or powershell) with some already existing Jenkins Plugin? The remote machine is not an agent, but the machine where some deployment using the FTP is being done after which I need to execute command for **Windows Service restart**.  
How this can be achieved? I thought that maybe **WinRMClient** plugin can be used for these purposes but I cannot execute it on my Linux docker agent (I have a separate topic open for this issue.)

I would be thankful for useful hints!  
Thanks a lot

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [November 25, 2021, 2:46pm UTC](https://community.jenkins.io/t/how-i-can-execute-windows-commands-on-remote-server-using-the-jenkins-declarative-pipeline/879/2 "2021-11-25T14:46:40Z")

</div>

I don’t think you need (or want) a dedicated plugin for that task. If you can execute a command from Linux that runs something on your Windows computer, then you can run that command inside a Jenkins Pipeline. Some examples of techniques that are available to run a Windows command remotely from Linux include:

- Secure shell - install and configure Microsoft’s OpenSSH server on your Windows computer, use `ssh` to start Windows programs from Linux
- winexe - install Linux `winexe` command and use it to start Windows programs from Linux
- xfreerdp - install Linux `xfreerdp` command and use it to start Windows programs from Linux

> <https://unix.stackexchange.com/questions/171331/how-to-execute-windows-commands-remotely-from-linux-machine-using-rdesktop-comma>

> **[Execute Windows Commands from Linux using winexe. Connect from Linux to...](https://easyoradba.com/2018/02/04/execute-windows-commands-from-linux-using-winexe-connect-from-linux-to-windows-without-ssh/)**
>
> Winexe – is a software on Linux which uses RPC to run remote commands and might even come with your…

---

<div class="post-metadata">

**Author:** ![cane](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@cane](https://community.jenkins.io/u/cane)\
**Post date:** [November 25, 2021, 2:59pm UTC](https://community.jenkins.io/t/how-i-can-execute-windows-commands-on-remote-server-using-the-jenkins-declarative-pipeline/879/3 "2021-11-25T14:59:41Z")

</div>

> [@MarkEWaite](#):
>
> Secure shell - install and configure Microsoft’s OpenSSH server on your Windows computer, use `ssh` to start Windows programs from Linux

Mark, thanks a lot for your very kind assistance. I wen through the links you provided me and I was wondering if you have some additional link with instructions for the: SSH installation and configuration for OpenSSH on windows. I suppose that assumes that we need to generate some keys, certificates, exchange files etc. Would it be possible to give me the best link which describes these steps in details? Thanks!!!

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [November 25, 2021, 3:12pm UTC](https://community.jenkins.io/t/how-i-can-execute-windows-commands-on-remote-server-using-the-jenkins-declarative-pipeline/879/4 "2021-11-25T15:12:35Z")

</div>

I use the Microsoft documentation for OpenSSH

> **[Install OpenSSH](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse)**
>
> Installing OpenSSH Client and Server for Windows.

---

<div class="post-metadata">

**Author:** ![saper](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/saper/32/138_2.png) [@saper](https://community.jenkins.io/u/saper)\
**Post date:** [November 25, 2021, 7:30pm UTC](https://community.jenkins.io/t/how-i-can-execute-windows-commands-on-remote-server-using-the-jenkins-declarative-pipeline/879/5 "2021-11-25T19:30:24Z")

</div>

In my environment we found that running a Jenkins agent was not a bad thing and this integrates nicely with a pipeline.
