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:tempservers.txt
$HostedRegFile = "tempCyclopsOfficeDocumentfix.reg"
foreach ($server in $servers)
{
$newfile = "\$serversc`$DownloadsRegistryFiles"
New-Item -ErrorAction SilentlyContinue -ItemType directory -Path \$serversC$DownloadsRegistryFiles
Copy-Item $HostedRegFile -Destination $newfile
Invoke-Command -ComputerName $server -ScriptBlock {
Start-Process -filepath "C:windowsregedit.exe" -argumentlist "/s C:DownloadsRegistryFilestest.reg"
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
$retucode = $?+":"+$lastexitcode;
$codearr = $retucode.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
Recent Questions...
ما را در سایت Recent Questions دنبال میکنید
برچسب:
نویسنده: استخدام کار
بازدید: 230
تاريخ: سه
شنبه
11 خرداد
1395 ساعت: 20:35