Changing remote computer registry

I was able to piece together some code, it works just fine on my local machine, but how do I get it to pull the computer names from my text file and use those, instead of performing the change on my machine?

 
#Ask for Admin Credentials
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }

Clear-Host

$Computers = Get-Content "C:\Users\JIM\Desktop\computerlist.txt"
$Path = "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Printers\Microsoft XPS Document Writer\DsSpooler"
$Property = "printShareName"
$Value = "XPSPrinter"

$results = foreach ($computer in $Computers)
{
    If (test-connection -ComputerName $computer -Count 1 -Quiet)
    {
        Try {
            Set-ItemProperty -Path $path -Name $Property -Value $Value -ErrorAction 'Stop'
            $status = "Success"
        } Catch {
            $status = "Failed"
        }
    }
    else
    {   
        $status = "Unreachable"
    }
    
    New-Object -TypeName PSObject -Property @{
        'Computer'=$computer
        'Status'=$status
    }
}

$results |
Export-Csv -NoTypeInformation -Path "c:\Users\JIM\Desktop\Results.csv"

Remote registry is tricky since you can’t use the registry PSProvider; you’re likely going to have to rewrite the whole thing to use WMI/CIM. Unfortunately, Set-Item ain’t gonna do it.

https://msdn.microsoft.com/en-us/library/aa394600(v=vs.85).aspx has examples in PowerShell.

Alternately, if Remoting is an option, then this is a lot easier for you. LMK if that’s the case and I’ll change my answer ;).

When you say “if Remoting is an option”, are you referring to the fact that we can remote desktop into it?

Lolz, definitely not. RDP is of the devil. PowerShell Remoting; as in, Invoke-Command. Enabled by default on server 2012 and later, I believe (maybe R2?), but you’d have to enable it with Enable-PSRemoting on clients and older servers.

slaps head I knew that
From my understanding, in order to enable PSRemoting, i would have to do that on each individual machine, then run a script that would change the registry value, right?

You can do it with GPO, too, if you’re in a domain environment. It’s in “Secrets of PowerShell Remoting.”

And then, yes, you’d basically just Invoke-Command your existing script (very slightly modified) to a whole list of computers, and sit back and drink whiskey while it runs.

Thank you Don, let me mess around with it some more and see what i can do. Appreciate your fast response.