running a script from a batch file


  1. Posts : 8
    windows 10
       #1

    running a script from a batch file


    I have a batch file that I use to install multiple pieces of software on new computers coming into our office. I have been manually starting up a PowerShell script and running it but I know there is a better way to do this.
    There are a couple of scripts that I would like to see working in the installation batch file. For all my other commands in the batch file, they run fine without having to run As Administrator.

    This is the cleanup script that I run at the end of the installation
    https://raw.githubusercontent.com/Sy...pDebloater.ps1

    Currently, I copy this script to the C:\Temp folder and rename it Clean.ps1
    Then I launch PowerShell in Administrator mode and run it. All manual
    The closest that I can come to running it is with the following command in my batch file
    Powershell.exe -noprofile -ExecutionPolicy Bypass -file C:\Temp\Clean.ps1
    But it doesn't run correctly. It's not being run as the administrator.
    Can anyone help me with this?
      My Computer


  2. Posts : 777
    Windows 7
       #2

    Run a PS script in elevated mode. Will ask for permission if you're not already Administrator.
    Code:
    powershell "Start-Process powershell -ArgumentList '-NoProfile -ExecutionPolicy -File C:\Temp\Clean.ps1' -Verb RunAs"
      My Computer


  3. Posts : 8
    windows 10
    Thread Starter
       #3

    Excellent, thank you, that DID the trick.

    - - - Updated - - -

    Hi again, so one other item that I would like to get working is running Delprof2.exe with PowerShell.

    Opening PowerShell as the Administrator
    Running C:\Temp\DelProf2.exe /u

    I figured I could run...
    Powershell.exe "Start-Process powershell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File C:\Temp\Delprof2.exe /u' -Verb RunAs"

    But that doesn't work
      My Computer


  4. Posts : 777
    Windows 7
       #4

    DelProf2.exe is an executable program, not a PS script.

    You're calling DelProf2 directly, so there is no interactive shell and you need to pass DelProf2's command-line arguments in ArgumentList.
    Code:
    powershell "Start-Process C:\Temp\DelProf2.exe -ArgumentList '/q' -Verb RunAs"

    If you're already running an elevated PS script, why not call DelProf2.exe from inside PS?
    Anything that isn't recognized as a legitimate PS command is assumed to be an outside executable to run.
    Code:
    Write-Output "Calling DelProf2"
    C:\Temp\DelProf2.exe /q
      My Computer


  5. Posts : 8
    windows 10
    Thread Starter
       #5

    Another great solution!!
    Thank you, that did the trick
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 16:39.
Find Us




Windows 10 Forums