2
2
I have tried creating a batch file using PsExec to update registry settings on remote computers without success so I am now trying to use Powershell. I have compiled the following script by using Google and playing about with scripts available on different forums.
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
if ($myWindowsPrincipal.IsInRole($adminRole))
{
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
$Host.UI.RawUI.BackgroundColor = "Darkred"
clear-host
}
else
{
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
$newProcess.Verb = "runas";
[System.Diagnostics.Process]::Start($newProcess);
exit
}
winrm quickconfig
$servers = Get-Content c:\temp\servers.txt
$HostedRegFile = "temp\OfficeDocumentfix.reg"
foreach ($server in $servers)
{
$newfile = "\\$servers\c`$\Downloads\RegistryFiles\"
New-Item -ErrorAction SilentlyContinue -ItemType directory -Path \\$servers\C$\Downloads\RegistryFiles\
Copy-Item $HostedRegFile -Destination $newfile
Invoke-Command -ComputerName $server -ScriptBlock {
Start-Process -filepath "C:\windows\regedit.exe" -argumentlist "/s C:\Downloads\RegistryFiles\test.reg"
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
$returncode = $?+":"+$lastexitcode;
$codearr = $returncode.split(":");
write-host $codearr[0];
write-host $codearr[1];
#echo Registry_updated_successfully
#:Failed
#echo Registry_update_failed
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
}
Now for my Problem, running the script, I get the following error
WinRM already is set up to receive requests on this machine.
WinRM already is set up for remote management on this machine.
Copy-item : Cannot find path 'C:\OfficeDocumentfix.reg' because it does not exist.
But the path is correct, is there something blatantly obviously wrong with the script I am using, this is my 2nd push into Powershell so any help would be appreciated
Please [edit] your question and show the
PsExec
call. – JosefZ – 2016-05-31T13:39:09.033