Results 1 to 7 of 7
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,531
    Thanks
    87
    Thanked 13 Times in 12 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
    24,268
    Thanks
    5
    Thanked 1,197 Times in 1,042 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,948
    Thanks
    421
    Thanked 1,605 Times in 1,449 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,531
    Thanks
    87
    Thanked 13 Times in 12 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,948
    Thanks
    421
    Thanked 1,605 Times in 1,449 Posts
    Chuck,

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

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    Banned Member
    Join Date
    Dec 2009
    Posts
    349
    Thanks
    13
    Thanked 35 Times in 33 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,531
    Thanks
    87
    Thanked 13 Times in 12 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
  •