Results 1 to 7 of 7
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Setting Execution Policies in PowerShell

    I tried to add

    Set-ExecutionPolicy RemoteSigned

    to Line 1 of profile.ps1 in in my Public folder, C:\Users\Public\WindowsPowerShell\PSProfile.ps1, but get the following error:

    Set-ExecutionPolicy : Access to the registry key
    'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\ 1\ShellIds\Microsoft.PowerShell' is denied. To change the execution
    policy for the default (LocalMachine) scope, start Windows PowerShell with the "Run as administrator" option. To
    change the execution policy for the current user, run "Set-ExecutionPolicy -Scope CurrentUser".
    At C:\Users\Public\WindowsPowerShell\PSProfile.ps1:6 char:1
    + Set-ExecutionPolicy RemoteSigned
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : PermissionDenied: ( [Set-ExecutionPolicy], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.Power Shell.Commands.SetExecutionPolicyComma

    Can't I set the Execution Policy in profile.ps1? If I can, then why am I getting this error?
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  2. #2
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,571
    Thanks
    5
    Thanked 1,056 Times in 925 Posts
    Try running Powershell with "Run as administrator" not just with an account which is a member of the administrative group.
    Joe

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Chuck,

    There is no need to place it in your profile as it is a set it once and forget it. As Joe said you need to set it while running PowerShell as Admin.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    And then, RG / Joe, would that setting last until I change it or only until the session closes?

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Chuck,

    It will persisit until you change it. HTH
    Last edited by RetiredGeek; 2016-07-29 at 11:37.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    3 Star Lounger djohnson's Avatar
    Join Date
    Dec 2009
    Location
    Delaware City, Delaware
    Posts
    323
    Thanks
    13
    Thanked 32 Times in 30 Posts
    Here is how you fix it. Open notepad, and paste this:
    Code:
    param([switch]$Elevated)
    
    function Test-Admin {
      $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
      $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
    }
    
    if ((Test-Admin) -eq $false)  {
        if ($elevated) 
        {
            # tried to elevate, did not work, aborting
        } 
        else {
            Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
    }
    
    exit
    }
    
    'running with full privileges'
    Then save it with a ps1 extension. Right click, and select run with powershell. Done.

  7. #7
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Thanks to the both of you...

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •