27 March 2013

How to run a Powershell script as administrator

Say you are deploying a package and need to run it as admin with elevated privileges. Of course if you are running the script manually, you can open up powershell with admin priviledges by running the cmd.exe as administrator. I haven't been able to find any easy ways of doing this within Powershell scripts, although it can be done. There is an easy way though if you use VBScript as a Powershell wrapper. Create the VBScript and point it to execute the Powershell script as admin. Here is how:


 Set oShell = CreateObject("Shell.Application")  
 oShell.ShellExecute "powershell", "-executionpolicy bypass -file test.ps1", "", "runas", 1  

That is all that is to it. Execute the VBScript and the Powershell script will be executed as administrator.

Related Posts:

  • BOOTMGR is missing after applying a WIM This is being caused by the 200 MB hidden partition windows creates when the partitioning is done before the OS is laid down. This is done to pre-configure the system for bitlocker, even if it is not going to be us… Read More
  • SCCM Automation Checklist I have a checklist of automation procedures I want to include in SCCM during the upgrade process from SMS 2003. Create a script that will test the WMI on all machines. If an error occurs, SCCM will create a ticket in SCSM… Read More
  • Autodesk Installation Error 1603 While installing Autodesk 2012, we were confronted with an error 1603. The error is caused by the Microsoft Visual C++, as outlined in this blog. Specifically, it is the design review portion of the package that requires the… Read More
  • Internet Access for an application during MDT or SCCM build You have an application that is installed during the build process of MDT or SCCM and it needs access to the internet to download additional files. There are some programs, such as Autodesk Revit, that you cannot download ev… Read More
  • SCCM Package Doesn't Update You have a small package in SCCM that you needed to make a couple of lines of changes in the deployment script and it doesn't seem to update when you update the package in SCCM. This is because the changes are so minute that… Read More

1 comments: