Need to enable PowerShell 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

<# 
.NOTES 
     Created on:       5/9/2014 3:46 PM 
     Created by:       Adam Bertram        
.DESCRIPTION 
     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. 
.EXAMPLE 
     .\Enable-PSRemotingRemotely.ps1 -Computername COMPUTER1 -PsExecPath C:\Psexec.exe 
.PARAMETER Computername 
     The remote computer to enable PS remoting on 
.PARAMETER PsExecPath 
     The file path where the Sysinternals' tool psexec is located 
#> 
[CmdletBinding()] 
param ( 
    [Parameter(Mandatory = $True, 
               ValueFromPipeline = $True, 
               ValueFromPipelineByPropertyName = $True)] 
    [string]$Computername, 
    [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)] 
            $computername 
        ) 
         
        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 
        } 
        $true 
    } 
     
    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 { 
     
}

Join the Jar Tippers on Patreon

It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!

Become a Patron!