Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

}