locked
Remotely enable PSRemoting RRS feed

  • Question

  • Hi guys,

    So, the scripting world is new to me but I’m trying to get a handle on it, and hope that you can help me.

    I’m working in a mixed environment; our domain contains XP clients and 2008R2 servers. All client computers have PS 2.0 installed.

    I want to be able to work with PSRemoting on other client computers. Of course I have Admin privileges and I ran the commands as admin.

    My problem is that I can't enable remoting through Group Policy. Our organization is really big and changing GPO will take forever because of IT policies and different approvals.

    Right now we have a few jobs we really need to execute and can’t wait till GPO changes are done.

    So actually, I’m looking for a way to enable remoting on remote machines in our domain. When I logon interactively to a machine and enable PSReomting, I’m able to work remotly on this machine after that. But I can't find a way to remotely enable PSReomting.

    I’ve tried to enable the winrm service through cmd, and then with PS, like this:

    SC \\server start winrm

    Then, from PS:

    foreach ($i in 'Computer') { Enable-PSRemoting -Force }

    Then I ran winrm quickconfig, and the result was:

    WinRM already is set up to receive requests on this machine

    WinRM already is set up for remote management on this machine

    After performing these steps, I tried remoting and got this error:

    "Connecting to remote server failed with the following error message: access is denied. for more info...."

    I went through every step in About_Remote_Troubleshooting but found nothing.

    After googling for hours I found nothing.

    Also, does anyone know if PS Active Directory module is available for XP? After some searching it looks like XP doesn’t support this module, but just to make sure.

    Thank you J

    Friday, November 25, 2011 8:34 AM

Answers

  • Hi guys,

    Thanks for the replay, great idea. i took your advice and created a task using the schtasks command.

    I placed a batch file in a network share, which runs a ps1 file with enable-psremoting -force command.

    Using the schtasks, i scheduled a task to run the script and everything went great.

    Work like a charm!


    Sunday, November 27, 2011 9:37 PM

All replies

  • for security reasons you cant run the commands remotely.
     
    you'd need to login and then run it.
     
    you could maybe do something like telnet to configure it perhaps? but im
    guessing it will still see and catch that.
     
    maybe remotely deploy a schedule task that runs the commands? that might
    work and shouldn’t be too hard.
     
    I've tried this and it seems to catch a lot of methods of remote config, I
    gave in quickly and went to GPO since its not too bad to get that deployed
    for me.
     
    schedule task is probably worth a try tho
     
     

    Justin Rich
    http://jrich523.wordpress.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, November 25, 2011 1:45 PM
  • AD module on XP

    Not supported on XP, but once you have PowerShell remoting, you can remote into your DC and use proxy functions so you have access to the cmdlets.

    Friday, November 25, 2011 11:39 PM
    Moderator
  • Hi guys,

    Thanks for the replay, great idea. i took your advice and created a task using the schtasks command.

    I placed a batch file in a network share, which runs a ps1 file with enable-psremoting -force command.

    Using the schtasks, i scheduled a task to run the script and everything went great.

    Work like a charm!


    Sunday, November 27, 2011 9:37 PM
  • Hi, I know this has been answered, but I feel using schtasks is overly complicated. I've found a better way and am posting it since this question is the top result in Google for the topic.

    First, you need to have a microsoft tool - psexec - http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx - download and extract to where ever.

    After that run cmd.exe, and navigate to whatever folder psexec has been extracted to (ie. cd C:\[path to psexec's containing folder)

    Then run this command:

    psexec \\[computer name] -u [admin account name] -p [admin account password] -h -d powershell.exe "enable-psremoting -force"

    That's it. Twiddle your thumbs for a couple minutes - enable-psremoting can sometimes take a while and the -d modifier just lets it happen in the background on the target remote machine, then you are good to go with all your psRemoting funtimes.

    You can also replace "\\[computer name]" with an ip address, or even "@C:\[path]\list.txt to automatically enable psRemoting on a big list of computers on your network. Very fast, very easy.

    Hope this is clear enough for the less experienced because most of what turns up on Google is not very helpful for this topic.

    • Proposed as answer by whatyousay Monday, July 23, 2012 9:23 PM
    Monday, July 23, 2012 9:23 PM
  • Great Article! Helped me save a lot of time by enabling the PSremoting remotely by using the Psexec tools as you suggested. Thanks!

    Tuesday, July 30, 2013 4:27 PM
  • There's also a nice set of PowerShell functions in the gallery:

    http://gallery.technet.microsoft.com/scriptcenter/Enable-PSRemoting-Remotely-6cedfcb0


    Tuesday, July 30, 2013 5:07 PM
  • Very helpful, thanks!
    Friday, January 24, 2014 11:59 AM
  • Hi,

    How would you use the functions since I am new to ps. Can you please give some example ie running against one computer and also running with multiple computers.

    Thanks,

    Friday, October 31, 2014 11:34 AM
  • Thanks whatyousay!  It worked for me!
    Thursday, February 26, 2015 5:26 PM
  • Great @whatyousay, I spent a good chunk of my day, and your use of the flag -d was what did the trick!!

    It was the missing piece of the puzzle with psexec.

    Do you know why when non interactive works and otherwise not?

    Friday, May 22, 2015 8:57 PM
  • You sir, are my hero today!!  Just saved me from 96 separate RDP sessions.

    Tuesday, June 16, 2015 7:37 PM
  • It's time to put this to bed once and for all. Do these 3 commands in powershell ISE: (I use PowerGUI Script Editor)

    CMD /c  SC \\Hostname start winrm

    PSEXEC \\hostname -s -h -d powershell.exe "enable-psremoting" -force (follow the previous  posts to set up PSEXEC)

    New-PSSession -ComputerName "hostname" (This is for testing purposes to verify it works)

    *Scripting outlaw vigilante"

    Wednesday, December 16, 2015 6:07 PM
  • I used powershell and psexec from the sysinternals suite. you can download sysinternals from Microsoft here:

    https://technet.microsoft.com/en-us/sysinternals/bb842062.aspx

    from there I did this worked great.

    <#
    Martin Gomez 2016 enable ps remoting on remote servers.

    you need to point $rs at your lsit of servers.
    point the CMD /c at wherever psexec is on the machine you are running from.

    you can test that this worked by running the berfore and after.

    Invoke-Command -ComputerName myremoteservername -ScriptBlock {Get-Process}
    #>

    $RS = Get-Content C:\temp\list.txt

    foreach ($s in $RS){
    $cmd1 = "cmd /c C:\Source\sysinternals\PsExec.exe \\$s -s winrm.cmd quickconfig -q"
    $cmd2 = "cmd /c C:\Source\sysinternals>PsExec.exe \\$s -s powershell.exe enable-psremoting -force"

    Invoke-Expression -Command $cmd1
    Invoke-Expression -Command $cmd2
    }

    Monday, November 14, 2016 10:51 PM
  • Why do you recycle an ancient post what has been marked as solved 5 years ago?

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Monday, November 14, 2016 11:30 PM
  • I used powershell and psexec from the sysinternals suite. you can download sysinternals from Microsoft here:

    https://technet.microsoft.com/en-us/sysinternals/bb842062.aspx

    from there I did this worked great.

    <#
    Martin Gomez 2016 enable ps remoting on remote servers.

    you need to point $rs at your lsit of servers.
    point the CMD /c at wherever psexec is on the machine you are running from.

    you can test that this worked by running the berfore and after.

    Invoke-Command -ComputerName myremoteservername -ScriptBlock {Get-Process}
    #>

    $RS = Get-Content C:\temp\list.txt

    foreach ($s in $RS){
    $cmd1 = "cmd /c C:\Source\sysinternals\PsExec.exe \\$s -s winrm.cmd quickconfig -q"
    $cmd2 = "cmd /c C:\Source\sysinternals>PsExec.exe \\$s -s powershell.exe enable-psremoting -force"

    Invoke-Expression -Command $cmd1
    Invoke-Expression -Command $cmd2
    }

    Doesn't work!


    \_(ツ)_/

    Monday, November 14, 2016 11:45 PM
    Moderator
  • Great answer!
    Tuesday, November 22, 2016 6:22 PM
  • After you run the script. You have to call that function. For example in Microsoft Technet Gallery, there's a cript for setting up WINRM listener on remote machine. After you run the script, you are going to type "set-winrmlistener" and you will be prompted for the computer name.
    Wednesday, August 9, 2017 6:17 PM
  • After you run the script. You have to call that function. For example in Microsoft Technet Gallery, there's a cript for setting up WINRM listener on remote machine. After you run the script, you are going to type "set-winrmlistener" and you will be prompted for the computer name.

    Please do not post off-topic answers to closed questions.  This thread was closed and answered 6 years ago.


    \_(ツ)_/

    Wednesday, August 9, 2017 6:23 PM
    Moderator
  • If you run VMware you can also use PowerCLI to remotely enable PS Remoting, Eg:

    Invoke-VMScript -vm FileServer01 -ScriptText {Enable-PSRemoting –force -ea silentlycontinue; Set-Service WinRM -StartMode Automatic -ea silentlycontinue ; Set-Item WSMan:localhost\client\trustedhosts -value * -Force -Confirm:$false -ea SilentlyContinue }}

    Tuesday, January 29, 2019 3:06 AM
  • I try this command psexec \\[computer name] -u [admin account name] -p [admin account password] -h -d powershell.exe "enable-psremoting -force"  and got password is incorrect but the password is correct using local admin and domain admin account. Why?
    Wednesday, May 22, 2019 5:21 PM