0

I am trying to execute a file via the CMD with Administrative privileges.

How can I open a cmd via command line with Administrative privileges.

I have to execute a script within a script.

 powershell -ExecutionPolicy ByPass -noprofile -command "&{ start-process powershell -ArgumentList '-noprofile -File C:\scripts\install_ims.ps1' -verb RunAs}"

I have tried this in a bat file, but it doesn't work when executed within the script.

Vini
  • 1,978
  • 8
  • 40
  • 82
  • Possible duplicate of [PowerShell: Running a command as Administrator](https://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator) – lit Nov 06 '18 at 15:23
  • Why is it that you need to invoke PowerShell twice? – lit Nov 06 '18 at 15:24
  • I am writing these in terraforms @lit. – Vini Nov 07 '18 at 08:34

1 Answers1

0

This should work fine for your purposes.

powershell -Command "Start-Process <filename> -Verb RunAs" 

This is copy-pasted from some Batch files that I finally added to GitHub in the last few days if you have questions, that's probably the best place to go. https://github.com/Benny121221/Batch-BS

Ben
  • 2,200
  • 20
  • 30