Windows 10: run a powershell command like a batch file

Discus and support run a powershell command like a batch file in Windows 10 Installation and Upgrade to solve the problem; I am working as a temp on a Windows 7 to Windows 10 migration team. We've encountered a problem with some software, and a solution has been found that... Discussion in 'Windows 10 Installation and Upgrade' started by SlickRCBD, Jul 25, 2020.

  1. SlickRCBD Win User

    run a powershell command like a batch file


    I am working as a temp on a Windows 7 to Windows 10 migration team.

    We've encountered a problem with some software, and a solution has been found that requires us to execute a a single command with PowerShell.

    However, the command is extremely long and complex, and very easy to make a typo. As an added hickup, some of the older laptops are being replaced at this time, and we are using crossover cables to migrate the users' files instead of clogging the network, which temporarily takes them offline as the new laptops shut off their wifi when we plug in an Ethernet cable for some aggravating reason the old win7 laptops stay online via wifi.



    Is there any way to make a batch file on a flash drive we can double-click on in order to execute the PowerShell command and fix the installs?

    Saving it as a .bat file does not work. Saving it as a .PS1 file tells us that it is blocked for security purposes.

    These are fresh images, and the PowerShell fixes the autoconfig, so any group policy changes won't be pushed untilafter the command is executed, plus we probably want to leave the security in place after the migration as the users are working from home due to COVID and bringing their laptops in for the migration or laptop replacement and I'm stuck sanitizing the computers.


    So, how can I make a file to double-click on and execute a single command in PowerShell the way I could for decades in command.com or cmd.com with a .bat file?


    BTW, I'm furloughed for the next few days next week while the higher up IT guys are trying to fix the issue, but I thought I'd take the initiative and ask how we can implement the solution at hand easier.

    The best I've come up with was to save the command as a .txt file, and copy and paste using Notepad.

    This is exactly the type of thing that if it was done with commmand.com or cmd.com I would have made a .bat file and been done with it.

    :)
     
    SlickRCBD, Jul 25, 2020
    #1

  2. Running PowerShell script as a batch file

    Hello Baldo,



    Thank you for writing to Microsoft Community Forums.



    I understand that you want to execute the PowerShell commands as a batch file.



    I tried executing the batch file on my machine but I was unable to execute it as the command was incomplete. However, after making some changes in the command I was able to execute the batch file.



    You can try the following command by saving it in a batch file and check if that helps.



    powershell –Command Get-AppxPackage Microsoft.3dBuilder | Remove-AppxPackage



    Also, as the query is related to running a PowerShell script using a batch file, I suggest you to post the issue on

    TechNet
    forums where we have professionals who have more knowledge about the issue.



    Hope it helps.



    Regards,

    Prakhar Khare

    Microsoft Community – Moderator
     
    Prakhar_Khare, Jul 25, 2020
    #2
  3. Try3 Win User
    Syntax for Batch file &/or powershell script to run multiple commands

    No. The opening command of that batch file requests admin privileges for a powershell session and that is why you got an admin prompt that you had to accept in order to run the batch file.

    By the way, why did you want to run the regsvr32 commands in a pwershell session anyway? You could have done the whole thing in a batch file without using powershell at all.

    Denis
     
  4. phrab Win User

    run a powershell command like a batch file

    Syntax for Batch file &/or powershell script to run multiple commands

    Thank you for this. I have a question though. This opens a command prompt as administrator. Is that what all batch files open?

    run a powershell command like a batch file [​IMG]
     
    phrab, Jul 25, 2020
    #4
Thema:

run a powershell command like a batch file

Loading...
  1. run a powershell command like a batch file - Similar Threads - run powershell command

  2. Batch File Command???

    in Windows 10 Gaming
    Batch File Command???: I want to run a batch file that starts a backup program, but does not execute the next command until that program completes? How do I do this? https://answers.microsoft.com/en-us/windows/forum/all/batch-file-command/3af2ce6b-ace3-43cb-b6fb-5cbff8998736
  3. Batch File Command???

    in Windows 10 Software and Apps
    Batch File Command???: I want to run a batch file that starts a backup program, but does not execute the next command until that program completes? How do I do this? https://answers.microsoft.com/en-us/windows/forum/all/batch-file-command/3af2ce6b-ace3-43cb-b6fb-5cbff8998736
  4. Starting batch file only opens command prompt versus running the batch file?

    in Windows 10 Gaming
    Starting batch file only opens command prompt versus running the batch file?: I'm trying to run one batch file, then another. Instead of running the 2nd batch file, it just opens another black screened command prompt with the name of the batch file as the first line in the command prompt? Any ideas why?...
  5. Starting batch file only opens command prompt versus running the batch file?

    in Windows 10 Software and Apps
    Starting batch file only opens command prompt versus running the batch file?: I'm trying to run one batch file, then another. Instead of running the 2nd batch file, it just opens another black screened command prompt with the name of the batch file as the first line in the command prompt? Any ideas why?...
  6. Syntax for Batch file &/or powershell script to run multiple commands

    in Windows 10 Support
    Syntax for Batch file &/or powershell script to run multiple commands: I wanted a batch file to run the following commands: Start Powershell as administrator cd "C:\Program Files\Macrium\Reflect" regsvr32 RContextMenu.dll regsvr32 RShellEx.dll I can get as far as: Code: echo Start "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" cd...
  7. Running PowerShell script as a batch file

    in Windows 10 Network and Sharing
    Running PowerShell script as a batch file: Can I run the Power Shell line: "C:\Windows\System32>get-appxpackage *3dbuilder* | remove-appxpackage" from a .Bat file? ***Original title: Removing bloatware***...
  8. Run Multiple Commands In Powershell?

    in Windows 10 Performance & Maintenance
    Run Multiple Commands In Powershell?: Hi, I have three drives in my PC. Two of them are SSD's and the third one is a mechanical HDD. I like to optimize them using Powershell. However, as it stands now. I'm running the commands separately for each of my drive, i.e. 1.) Optimize-Volume -DriveLetter C -ReTrim...
  9. How to run batch file with powershell

    in Windows 10 Network and Sharing
    How to run batch file with powershell: I created a basic batch file that uses "net share" to share a local path. I saved the batch file. When I double click the file I get "access is denied"... note, I am logged on as a admin. Anyways... I figure it has to be run using power shell. I do not know much about...
  10. Run Multiple Commands In Powershell?

    in Windows 10 Performance & Maintenance
    Run Multiple Commands In Powershell?: Good job, @lx07. Of course, you had the benefit of knowing the OP wanted to run the same command on 3 targets. Had I been armed with that same information, I might have made that same suggestion, too. That's why we're better working together than working individually. --Ed--