Windows 10: On how to run a .ps1 file as Administrator

Discus and support On how to run a .ps1 file as Administrator in Windows 10 Support to solve the problem; Hello everyone, If you have had a chance of going through the great Brink's Tutorial Apps - Uninstall in Windows 10 (I strongly advice you do), you... Discussion in 'Windows 10 Support' started by Lmbrt, May 15, 2016.

  1. Lmbrt Win User

    On how to run a .ps1 file as Administrator


    Hello everyone,

    If you have had a chance of going through the great Brink's Tutorial Apps - Uninstall in Windows 10 (I strongly advice you do), you may have noticed that, if you wish to automatize, at least to a certain extent, the procedure of getting rid of Windows 10 pre-installed bloatware (sorry, Apps would sound much better), you will inescapably bump into the need of creating a tailored .ps1 file.

    More specifically, you may want to copy and paste into a text editor like Notepad your customized set of instructions and then saving it with the extension .ps1 rather than .txt (or, which is the same, save it as a .txt file and then, disregarding Windows warnings, change its extension to .ps1)

    I hope an example might help. Let us assume I wish to uninstall, for instance, Alarms & Clock, Calendar and Mail, Candy Crush Soda Saga and Microsoft Solitaire Collection for all users. IMHO your file should be like this:

    Get-appxpackage -allusers *windowsalarms* | Remove-AppxPackage
    Get-appxpackage -allusers *windowscommunicationsapps* | Remove-AppxPackage
    Get-appxpackage -allusers *CandyCrushSodaSaga* | Remove-AppxPackage
    Get-appxpackage -allusers *solitairecollection* | Remove-AppxPackage

    So far so good, copy and paste all of the above into Notepad, save it as a .ps1 file and everybody's content. Apart from the fact that when you launch it with PowerShell, which is the final purpose of the whole iteration, it inevitably crashes due to the fact that, apparently, for these kind of instructions you need Administraor's privileges. That is, to be even more clear, those privileges you get when you right-click on PowerShell in Menu and select Run as Administrator.

    Which brings us to the question: how do I run a .ps1 file in PowerShell as Administrator? *Confused

    Kindly note that I am logged in my PC's as Administrator (single user, as a matter of fact).

    Thank you all in advance. *Smile

    :)
     
    Lmbrt, May 15, 2016
    #1

  2. how do i run a notepad file as administrator

    how do i run a notepad file as administrator. I'm trying to stop the infuriating windows 10 update by running a notepad file as follows: This is saved on my desktop and apparently i need to do this every day!!

    net stop wuauserv

    net stop cryptSvc

    net stop bits

    net stop msiserver

    Ren C:\Windows\SoftwareDistribution SoftwareDistribution.old

    Ren C:\Windows\System32\catroot2 Catroot2.old

    net start cryptSvc

    net start bits

    net start msiserver
     
    PGillespie59, May 15, 2016
    #2
  3. how do i run a notepad file as administrator

    What I would do would be to open a command prompt as administrator window and run the script there.
     
    Brian Tillman [MVP-Outlook], May 15, 2016
    #3
  4. Kari Win User

    On how to run a .ps1 file as Administrator

    Add following command in your batch file to launch a PowerShell script elevated:

    Code: PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Unrestricted -File ""PS_Script_Path&Name.ps1""' -Verb RunAs}";[/quote] As you cannot call an elevated PowerShell from command line, the command first starts normal PowerShell, which then in its turn calls another PowerShell process, this time elevated (the -Verb RunAs switch).

    This works *Smile
     
  5. Lmbrt Win User
    [/quote]
    Thanks a lot for your answer! *Smile

    As I'm all thumbs, I am having problems "to set" the correct .ps1 file name... *Confused

    That is, if for instance my file is C:\Users\UserName\Desktop\-online.ps1, the command would be the following?

    PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Unrestricted -File ""PS_Script_C:\Users\UserName\Desktop\-online.ps1""' -Verb RunAs}";

    I know, that is a shameful question. *Redface

    Sorry to bother and thank you very much in advance.
     
    Lmbrt, May 22, 2016
    #5
  6. Kari Win User
    No! The highlighted part is wrong, shouldn't be there.

    You replace the PS_Script_Path&Name.ps1 in my example with your PS script path and name, in this example of yours the command would be as follows:

    Code: PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Unrestricted -File ""C:\Users\UserName\Desktop\-online.ps1""' -Verb RunAs}";[/quote]
     
  7. Lmbrt Win User
    [/quote]
    As I said, I'm all thumbs. *Redface

    Thank you very much indeed! *Biggrin

    I'll try and I will keep you posted...
     
    Lmbrt, May 22, 2016
    #7
  8. Anderson Win User

    On how to run a .ps1 file as Administrator

    just a question guys:
    How can I run this script below using the Windows Credentials ? "-credential $credential" (for example):
    PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Unrestricted -File ""C:\Users\UserName\Desktop\-online.ps1""' -Verb RunAs}";
     
    Anderson, Oct 23, 2016
    #8
  9. Brink
    Brink New Member
Thema:

On how to run a .ps1 file as Administrator

Loading...
  1. On how to run a .ps1 file as Administrator - Similar Threads - run ps1 file

  2. Problems running a ps1 script

    in Windows 10 Gaming
    Problems running a ps1 script: I have been trying to run the script below but keep getting error messages shown in attached screenshots which I assume is to do with access. The script ran perfectly before I did a Window 11 reinstall recently. Any help in laymans terms on how to resolve would be greatly...
  3. Problems running a ps1 script

    in Windows 10 Software and Apps
    Problems running a ps1 script: I have been trying to run the script below but keep getting error messages shown in attached screenshots which I assume is to do with access. The script ran perfectly before I did a Window 11 reinstall recently. Any help in laymans terms on how to resolve would be greatly...
  4. How to not run as administrator?

    in Windows 10 Software and Apps
    How to not run as administrator?: How do I get a program to not run as administrator? I have tried going into the compatibility tab and unchecking the box but that doesn't work. https://answers.microsoft.com/en-us/windows/forum/all/how-to-not-run-as-administrator/6039d6d0-7961-4d0d-8e84-5750ae579c57
  5. How to not run as administrator?

    in AntiVirus, Firewalls and System Security
    How to not run as administrator?: How do I get a program to not run as administrator? I have tried going into the compatibility tab and unchecking the box but that doesn't work. https://answers.microsoft.com/en-us/windows/forum/all/how-to-not-run-as-administrator/6039d6d0-7961-4d0d-8e84-5750ae579c57
  6. how to run as administrator

    in AntiVirus, Firewalls and System Security
    how to run as administrator: how to run as administrator https://answers.microsoft.com/en-us/windows/forum/all/how-to-run-as-administrator/0203dd74-446d-4447-9443-dbf1c627879d
  7. How to run a .bat file as administrator in startup?

    in Windows 10 Support
    How to run a .bat file as administrator in startup?: Hello. As BitDefender as an ongoing error, I want to run a small "bdfix.bat" at login time. But this .bat file MUST be run as an administrator to work. How do I do that? *Redface 120997
  8. Add or remove Run as Administrator to PS1 File Context Menu in Windows 10

    in Windows 10 News
    Add or remove Run as Administrator to PS1 File Context Menu in Windows 10: [ATTACH] The main security measure on any operating system is the privileges. This means that the execution of any process or simply a program can be done at various stages. Mostly, this decision is taken care of by the operating system [...] This post Add or remove Run as...
  9. How to run File Explorer as Administrator

    in Windows 10 Support
    How to run File Explorer as Administrator: What I don't understand is why with administrator rights, I can't access or delete files or even save files to the Windows folder. I also don't have the option if I right click to run File Explorer with Administrator rights. [img] If I Right Click on another...
  10. Run as administrator - Add to PS1 File Context Menu in Windows 10

    in Windows 10 Tutorials
    Run as administrator - Add to PS1 File Context Menu in Windows 10: How to: Run as administrator - Add to PS1 File Context Menu in Windows 10 How to Add 'Run as administrator' to PS1 File Context Menu in Windows 10 Some legitimate applications require a full administrator access token (elevated) to perform their functions or tasks. For...

Users found this page by searching for:

  1. run ps1 as administrator

    ,
  2. run .ps1 as administrator

    ,
  3. run .ps1 as admin

    ,
  4. run ps1 file as admin,
  5. run ps1 as admin,
  6. how to run .ps1 as admin,
  7. how to run ps1 as admin,
  8. run .ps1 file as administrator,
  9. run ps1 script as administrator,
  10. how to .ps1 administrator,
  11. lounch powershell with administrator privilieges and run the command PS C:\OUStructure.ps1,
  12. get-appxpackage as admin ps1,
  13. run a ps1 file as administrator,
  14. windows exec ps1 program with admin,
  15. .ps1 as admin