# Add registry key

**URL:** <https://forums.powershell.org/t/add-registry-key/2835>\
**Category:** PowerShell Help\
**Created:** [July 16, 2014, 2:15am UTC](https://forums.powershell.org/t/add-registry-key/2835 "2014-07-16T02:15:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr-jacko](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@mr-jacko](https://forums.powershell.org/u/mr-jacko)\
**Post date:** [July 16, 2014, 2:15am UTC](https://forums.powershell.org/t/add-registry-key/2835/1 "2014-07-16T02:15:37Z")

</div>

I have to run this command remotely:  
set-ItemProperty-Path 'hklm: \ \ SOFTWARE \ Microsoft \ PowerShell \ 1 \ ShellIds \ Microsoft.PowerShell '-Name “ExecutionPolicy”-Value “RemoteSigned”  
It only works if I manually start Powershell in “Run as Administrator”  
you can run it automatically?  
I used this command:

$args = @’  
powershell.exe -Command {  
set-ItemProperty -Path 'hklm:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name “ExecutionPolicy” -Value “RemoteSigned”  
}  
'@  
Start-Process -ArgumentList $args -Verb RunAs PowerShell

I get the following error: “The execution of scripts is disabled on your system”  
I would just bypass this restriction …

---

<div class="post-metadata">

**Author:** ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)\
**Post date:** [July 16, 2014, 2:32am UTC](https://forums.powershell.org/t/add-registry-key/2835/2 "2014-07-16T02:32:23Z")

</div>

Jacko, please see example of running remote commands in the post [https://powershell.org/forums/topic/powershell-ruan-as-administrator/](https://powershell.org/forums/topic/powershell-ruan-as-administrator/)

---

<div class="post-metadata">

**Author:** ![mr-jacko](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@mr-jacko](https://forums.powershell.org/u/mr-jacko)\
**Post date:** [July 16, 2014, 3:06am UTC](https://forums.powershell.org/t/add-registry-key/2835/3 "2014-07-16T03:06:01Z")

</div>

The problem is that I would like to overcome the error “” The execution of scripts is disabled on your system. "  
It only works if I start, first and manually, Powershell in “run as administrator”  
I would like to start running the script automatically without any manual intervention and to do this I need to be able to write the key “ExecutionPolicy” in the registry …  
I hope I have explained the problem in an understandable way…

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [July 16, 2014, 5:34am UTC](https://forums.powershell.org/t/add-registry-key/2835/4 "2014-07-16T05:34:23Z")

</div>

I think you don’t need to modify the registry value directly.

Two easy options:

1. Use a Group Policy to set the PowerShell execution policy for all machines.
2. Invoke-Command -ComputerName client1, client2 -ScriptBlock { Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force }

Best,  
Daniel

---

<div class="post-metadata">

**Author:** ![mr-jacko](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@mr-jacko](https://forums.powershell.org/u/mr-jacko)\
**Post date:** [July 16, 2014, 6:48am UTC](https://forums.powershell.org/t/add-registry-key/2835/5 "2014-07-16T06:48:58Z")

</div>

Unfortunately PCs are in remote locations and not on the same LAN.  
The first method can be applied using a script?  
The method 2 is applicable on PCs that are outside the LAN?  
They are not in the domain and the operators have little computer experience …  
So I wanted to create a script that should only be performed by the operator …

---

<div class="post-metadata">

**Author:** ![mr-jacko](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@mr-jacko](https://forums.powershell.org/u/mr-jacko)\
**Post date:** [July 16, 2014, 10:02am UTC](https://forums.powershell.org/t/add-registry-key/2835/6 "2014-07-16T10:02:59Z")

</div>

In this way it works:  
Set-ExecutionPolicy RemoteSigned –Scope CurrentUser -Force

$args = @’  
powershell.exe -Command {  
set-ItemProperty -Path 'hklm:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name “ExecutionPolicy” -Value “RemoteSigned”  
}  
'@  
Start-Process -ArgumentList $args -Verb RunAs PowerShell

(thanks to the suggestion by Alexander Johansson)  
How can I run the command Set-ExecutionPolicy RemoteSigned –Scope CurrentUser -Force automatically without opening the powershell shell and run the command manually?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:47pm UTC](https://forums.powershell.org/t/add-registry-key/2835/7 "2024-05-16T20:47:48Z")

</div>

Closed on May 16, 2024, 8:47pm UTC


