title: How to run powershell command from azure devops pipeline to on-premises remote server
body: <p>​Hello all</p>
  <p>​I've added all the IP range listed in <a href="https://devblogs.microsoft.com/devops/new-ip-firewall-rules-for-azure-devops/" rel="nofollow noreferrer">https://devblogs.microsoft.com/devops/new-ip-firewall-rules-for-azure-devops/</a>  into my firewall. But still im not able to run powershell command from azure devops pipeline YAML to my on-premises windows server. Every time im getting new IP from microsoft, and that are not listed in above mentioned site.</p>
  <p>Im able to connect to server with my local machine using below powershell command</p>
  <p>below is my yaml pipeline script</p>
  <pre><code>pool:
  vmImage: 'windows-latest'
  
  stages:
  - stage: 'Deploy'
    jobs:
  - deployment: 'Deploy'
  environment: 'stage'
  strategy:
    runOnce:
      deploy:
        steps:
        - task: PowerShell@2
          inputs:
            targetType: 'inline'
            script: |
              $so = New-PsSessionOption –SkipCACheck -SkipCNCheck
              $username='myUserName'
              $password='myPassword'
              $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
              $credentials = New-Object System.Management.Automation.PSCredential($username, $secpasswd)
              Enter-PSSession -ComputerName xyz.com -Credential $credentials -UseSSL -SessionOption $so
              write-output 'host name is '+$(hostname)
  </code></pre>
  <p>Im getting error :</p>
  <p>Enter-PSSession : Connecting to remote server xyz.com failed with the following error message : WinRM cannot   complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the   network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By   default, the WinRM firewall exception for public profiles limits access to remote computers within the same local   subnet. For more information, see the about_Remote_Troubleshooting.</p>
  <p>Is it issue releated to firewall or my approach is wrong to execute Powershell script using azure devops?</p>