6

I have Windows 10 and run some PowerShell commands through the Outlook COM object. This requires PowerShell to be running the same level of access (running as admin or user) as Outlook.

As I need PowerShell to be running as administrator for other pieces I set Outlook to always run as admin too, no problem. The issue is when I open the ISE I now can't access the Outlook objects.

There doesn't appear to be any way to set the ISE to always run as admin. The Compatibility tab is missing (though not on PowerShell itself?) and the registry keys in ...Windows NT\AppCompatibility did nothing. I'd disable UAC completely but of course it's not possible in Windows 10 without screwing over a bunch of other stuff.

Any ideas? And no I don't particularly feel like right clicking the icon each time as I often open scripts directly.

UPDATE: Outlook complains it can't index as admin and the ISE doesn't recognise my network drives as admin so the lesser of two evils is just run both as a user. Incidentally, the Compatibility tab has disappeared from the PowerShell exe now too, thanks Microsoft...

3 Answers 3

7

Here are 2 different options you can use to start ISE as admin:

  1. You can create/edit a shortcut to the powershell_ise.exe executable file and edit the properties for that shortcut to Run as Administrator.

enter image description here

  1. You can start PowerShell ISE as admin by Start-Process powershell_ise -verb RunAs.
7
  • No, it's 2 different options.
    – bentek
    Oct 29, 2015 at 16:29
  • Updated answer to clarify that.
    – bentek
    Oct 29, 2015 at 16:32
  • I Appreciate the effort to improve the answer.
    – Ramhound
    Oct 29, 2015 at 16:33
  • 1
    This does not resolve the issue as if I open the ISE by double clicking a script the ISE opens as a restricted user. I would need to open the ISE from the shortcut every time. Seems that's the direction Microsoft are going though: You can do it this way and it does work, but not as well as it did in Windows 7 / Server 2008 Oct 30, 2015 at 15:47
  • Can you set the script properties to run as admin then?
    – bentek
    Oct 30, 2015 at 17:53
2

I came across this many months after the post, but I think my comment is helpful.

@Deadly-Bagel No, the script is just a file so it doesn't "run".

While a script is just a file, it can certainly contain functions. One of those functions can be setup to run as the first process in that script file. That function can be used to determine whether or not the current session is running as an administrator. If it is not, it can self-elevate (assuming the logged-in user has admin rights).

    function Use-RunAs
    {    
    # Check if script is running as Adminstrator and if not use RunAs 
    # Use Check Switch to check if admin 

    param([Switch]$Check) 

    $IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()` 
    ).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") 

    if ($Check) { return $IsAdmin }     

    if ($MyInvocation.ScriptName -ne "") 
    {  
        if (-not $IsAdmin)  
        {  
            try 
            {  
                $arg = "-file `"$($MyInvocation.ScriptName)`"" 
                Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList $arg -ErrorAction 'stop'  
            } 
            catch 
            { 
                Write-Warning "Error - Failed to restart script with runas"  
                break               
            } 
            exit # Quit this session of powershell 
        }  
    }  
    else  
        {  
            Write-Warning "Error - Script must be saved as a .ps1 file first"  
            break  
        }
    } 

    Use-RunAs

I hope this helps your situation. If not, I'd be happy to revisit.

1
  • That's if you're executing the script, my problem was that the ISE opens as a user when editing the script and was therefore restricted. Might work if you limited yourself to testing with F8... Unfortunately I found that when the ISE runs as admin it loses access to all my network drives for some reason, and Outlook was complaining at being admin so I dropped them both to user and the stuff that needs testing as admin (most of it) I just copy to an admin console. Having said that, I think I have a different use for this script so thanks for taking the time =) Jan 9, 2018 at 9:16
1

I'm assuming you are admin on the said PC otherwise you wouldn't be asking to do such, You can Completely ignore UAC Prompt and just run everything in elevated mode without having to click Yes or No! to do so, follow these steps:

  1. From the start menu, go to "Edit Group Policy"
  2. Go to this path: Computer Configuration >> Windows Settings >> Security Settings >> Local Policies >> Security Options
  3. Under "Policy", find "User Account Control: Behavior of the elevation prompt for administrators in Admin Approval mode
  4. Change settings to elevate without prompting.

That's it!

3
  • 1
    That opens up a whole ton of security issues, especially if you're connecting that computer to the Internet. Hackers just love wide open computers!
    – RobH
    Jun 26, 2023 at 23:00
  • "Elevate without prompting" - yes but presumably the application still has to ask to elevate, and PowerShell will still run as a user unless I explicitly tell it otherwise. Overall UAC is just a PITA, I've just learned to deal with it. Jun 27, 2023 at 16:30
  • I personally hated it when it asked for UAC everytime, that's when I learnt about this. if you're an admin, trust me this simple trick saves you a ton of clicking "Yes"
    – Onluck
    Jun 27, 2023 at 18:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .