Add registry key

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Mr. Jacko Mr. Jacko 2 years, 4 months ago.

  • Author
    Posts
  • #17193
    Profile photo of Mr. Jacko
    Mr. Jacko
    Participant

    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
    Profile photo of Sam Boutros
    Sam Boutros
    Participant

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

  • #17199
    Profile photo of Mr. Jacko
    Mr. Jacko
    Participant

    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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
      Profile photo of Mr. Jacko
      Mr. Jacko
      Participant

      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
    Profile photo of Mr. Jacko
    Mr. Jacko
    Participant

    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?

You must be logged in to reply to this topic.