Ask Your Question
4

How can one use Powershell commands with Jenkins via winrm?

asked 2021-09-03 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-11-12 05:00:00 +0000

bukephalos gravatar image

To use PowerShell commands with Jenkins via WinRM, follow these steps:

  1. Install the PowerShell plugin in Jenkins.
  2. Install the WinRM plugin in Jenkins.
  3. Configure the WinRM plugin with the details of the target machine and the credentials for authentication.
  4. Open the build job in Jenkins and add a new build step to execute a PowerShell script.
  5. In the PowerShell script, use the Invoke-Command cmdlet to execute the desired PowerShell commands on the target machine via WinRM.

Example PowerShell script:

$target = "target-machine"

$username = "domain\username"

$password = "password"

$securePassword = ConvertTo-SecureString -AsPlainText $password -Force

$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)

Invoke-Command -ComputerName $target -Credential $credential -ScriptBlock {

    # Insert PowerShell commands here

}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-03 11:00:00 +0000

Seen: 10 times

Last updated: Nov 12 '22