I am running my powershell from my machine as an administrator domain account that as local admin access on a server. I am trying to create a registry key with the below and the code works to copy my directory, but when trying to create the new registry key it fails.
When I run it I get:
New-Item : Requested registry access is not allowed.
At C:\Temp\mytest.ps1:13 char:13
+ New-Item -Path $regpath -Name GIL-Login -Value "C:\Program Files (x8 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH...rentVersion\Run:String) [New-Item], SecurityException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.NewItemCommand
Code:
# Check if you can ping list of servers
$servers = get-content "C:\Temp\servers.txt"
$pingable = @()
$notpingable = @()
$regpath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
foreach ($s in $servers) {
if (Test-Connection -ComputerName $s -Quiet -Count 1)
{
$pingable += $s
write-host = "Connect $s"
Copy-Item $source -Destination \\$servers\$dest -Recurse -Force
New-Item -Path $regpath -Name GIL-Login -Value "C:\Program Files (x86)\Chevron\GIL Login\GILogin.exe"
}
else
{
$notpingable += $s
write-host = "Failed $s"
}
}
When I run it I get:
New-Item : Requested registry access is not allowed.
At C:\Temp\mytest.ps1:13 char:13
+ New-Item -Path $regpath -Name GIL-Login -Value "C:\Program Files (x8 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH...rentVersion\Run:String) [New-Item], SecurityException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.NewItemCommand