Add registry key

Welcome Forums General PowerShell Q&A Add registry key

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
4 years, 7 months ago.

  • Author
    Posts
  • #17193

    Participant
    Points: 0
    Rank: Member

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

  • #17195

    Participant
    Points: 176
    Helping Hand
    Rank: Participant

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

  • #17199

    Participant
    Points: 0
    Rank: Member

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

  • #17205

    Moderator
    Points: 24
    Team Member
    Rank: Member

    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

    • #17206

      Participant
      Points: 0
      Rank: Member

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

  • #17209

    Participant
    Points: 0
    Rank: Member

    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?

The topic ‘Add registry key’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort