Enable PS Remoting Remotely

Adam Bertram

Adam Bertram

Read more posts by this author.

Need to enable PS Remoting remotely? It seems like a chicken and egg thing but by using psexec, you can make it happen with this PowerShell script.

Download this Enable-PSRemotingRemotely script via the Technet Script Repository

     Created on:       5/9/2014 3:46 PM 
     Created by:       Adam Bertram        
     This script provides an option to enable PS Remoting....remotely!  It uses Sysinternals' tool psexec 
     to connect to a remote computer and run winrm quickconfig. 
     .\Enable-PSRemotingRemotely.ps1 -Computername COMPUTER1 -PsExecPath C:\Psexec.exe 
.PARAMETER Computername 
     The remote computer to enable PS remoting on 
     The file path where the Sysinternals' tool psexec is located 
param ( 
    [Parameter(Mandatory = $True, 
               ValueFromPipeline = $True, 
               ValueFromPipelineByPropertyName = $True)] 
    [Parameter(Mandatory = $False, 
               ValueFromPipeline = $False, 
               ValueFromPipelineByPropertyName = $False)] 
    [string]$PsExecPath = 'C:\PsExec.exe' 
begin { 
    ## http://www.leeholmes.com/blog/2009/11/20/testing-for-powershell-remoting-test-psremoting/ 
    function Test-PsRemoting { 
        param ( 
            [Parameter(Mandatory = $true)] 
        try { 
            $errorActionPreference = "Stop" 
            $result = Invoke-Command -ComputerName $computername { 1 } 
        } catch { 
            Write-Verbose $_ 
            return $false 
        ## I've never seen this happen, but if you want to be 
        ## thorough.. 
        if ($result -ne 1) { 
            Write-Verbose "Remoting to $computerName returned an unexpected result." 
            return $false 
    if (!(Test-Connection $Computername -Quiet -Count 1)) { 
        throw 'Computer is not reachable' 
    } elseif (!(Test-Path $PsExecPath)) { 
        throw 'Psexec.exe not found'     
process { 
    if (Test-PsRemoting $Computername) { 
        Write-Warning "Remoting already enabled on $Computername" 
    } else { 
        Write-Verbose "Attempting to enable remoting on $Computername..." 
        & $PsExecPath "\\$Computername" -s c:\windows\system32\winrm.cmd quickconfig -quiet 2>&1> $null 
        if (!(Test-PsRemoting $Computername)) { 
            Write-Warning "Remoting was attempted but not enabled on $Computername" 
        } else { 
            Write-Verbose "Remoting successfully enabled on $Computername" 
end { 

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!