Author Posts

March 30, 2018 at 8:47 pm

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 }


$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"
        $status = "Unreachable"
    New-Object -TypeName PSObject -Property @{

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

March 30, 2018 at 8:49 pm

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. 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 ;).

March 30, 2018 at 8:54 pm

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

March 30, 2018 at 8:56 pm

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.

March 30, 2018 at 8:59 pm

*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?

March 30, 2018 at 9:00 pm

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.

March 30, 2018 at 9:25 pm

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