How do you run the PowerShell command - Enable-PSRemoting - globally on the desktop machines?

Hi Experts,

I have a script to gather Administrator information from each Windows 7 desktop or Windows 2008 server but I'm not sure how to run the command 'Enable-PSRemoting' globally so the script run successfully and doesn't display the 'RPC is Unavailable' error.

Thank you,
CuriousMAUserAsked:
Who is Participating?
 
Steve WhitcherSystems AdministratorCommented:
0
 
McKnifeCommented:
Hi.

I'm quite sure there's a way with GPOs. Did you drill through the gpo reference, yet? http://www.microsoft.com/en-us/download/details.aspx?id=25250
0
 
CuriousMAUserAuthor Commented:
Hi Steve,

Thank you. The final comment states an important remote command, 'winrm quickconfig -q'  which needs to execute manually on every remote desktop once. Wow. Fortunately, we only have 708 desktops, the Anonymous response has 5000 systems. Yikes.

Thank you, again.
Tom
0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
Steve WhitcherSystems AdministratorCommented:
I wasn't at my desk yesterday, so I couldn't dig up this reference.  I thought I'd throw it out there this morning as another option.  Lee Holmes offers a script in his book "Windows Powershell Cookbook" which uses WMI to remotely enable powershell remoting.  The Powershell Cookbook module is available online and includes this script as a function "Enable-RemotePSRemoting".  Here is the script itself, if you don't want to get the module for some reason:

    ##############################################################################
    ##
    ## Enable-RemotePsRemoting
    ##
    ## From Windows PowerShell Cookbook (O'Reilly)
    ## by Lee Holmes (http://www.leeholmes.com/guide)
    ##
    ##############################################################################
    
    <#
    
    .SYNOPSIS
    
    Enables PowerShell Remoting on a remote computer. Requires that the machine
    responds to WMI requests, and that its operating system is Windows Vista or
    later.
    
    .EXAMPLE
    
    PS > Enable-RemotePsRemoting <Computer>
    
    #>
    
    param(
        ## The computer on which to enable remoting
        $Computername,
    
        ## The credential to use when connecting
        $Credential = (Get-Credential)
    )
    
    Set-StrictMode -Version 3
    
    $VerbosePreference = "Continue"
    
    $credential = Get-Credential $credential
    $username = $credential.Username
    $password = $credential.GetNetworkCredential().Password
    
    $script = @"
    
    `$log = Join-Path `$env:TEMP Enable-RemotePsRemoting.output.txt
    Remove-Item -Force `$log -ErrorAction SilentlyContinue
    Start-Transcript -Path `$log
    
    ## Create a task that will run with full network privileges.
    ## In this task, we call Enable-PsRemoting
    schtasks /CREATE /TN 'Enable Remoting' /SC WEEKLY /RL HIGHEST ``
        /RU $username /RP $password ``
        /TR "powershell -noprofile -command Enable-PsRemoting -Force" /F |
        Out-String
    schtasks /RUN /TN 'Enable Remoting' | Out-String
    
    `$securePass = ConvertTo-SecureString $password -AsPlainText -Force
    `$credential =
        New-Object Management.Automation.PsCredential $username,`$securepass
    
    ## Wait for the remoting changes to come into effect
    for(`$count = 1; `$count -le 10; `$count++)
    {
        `$output = Invoke-Command localhost { 1 } -Cred `$credential ``
            -ErrorAction SilentlyContinue
        if(`$output -eq 1) { break; }
    
        "Attempt `$count : Not ready yet."
        Sleep 5
    }
    
    ## Delete the temporary task
    schtasks /DELETE /TN 'Enable Remoting' /F | Out-String
    Stop-Transcript
    
"@
    
    $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($script)
    $encoded = [Convert]::ToBase64String($commandBytes)
    
    Write-Verbose "Configuring $computername"
    $command = "powershell -NoProfile -EncodedCommand $encoded"
    $null = Invoke-WmiMethod -Computer $computername -Credential $credential `
        Win32_Process Create -Args $command
    
    Write-Verbose "Testing connection"
    Invoke-Command $computername {
        Get-WmiObject Win32_ComputerSystem } -Credential $credential

Open in new window

0
 
CuriousMAUserAuthor Commented:
Thank you, Steve.

Three books I have which I'm still digesting are:
PowerShell Deep Dives - Jeffery Hicks
Windows PowerShell Best Practices - Ed Wilson
PowerShell In Depth - Don Jones, Jeffery Hicks & Richard Siddaway

I'll check out the PowerShell Cookbook. Thank you.
0
 
McKnifeCommented:
0
 
CuriousMAUserAuthor Commented:
Thank you, more information, the better.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.