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

Discus and support Syntax for Batch file &/or powershell script to run multiple commands in Windows 10 Support to solve the problem; I wanted a batch file to run the following commands: Start Powershell as administrator cd "C:\Program Files\Macrium\Reflect" regsvr32 RContextMenu.dll... Discussion in 'Windows 10 Support' started by phrab, Apr 2, 2020.

  1. phrab Win User

    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:
    After that I get error messages.

    I was able to create an Autohotkey script that will do this:

    Code:
    but I don't know the syntax to create a batch file or powershell script to do this.

    Thank you in advance!

    :)
     
    phrab, Apr 2, 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, Apr 2, 2020
    #2
  3. Rohn007 Win User
    Batch rename files using ForFiles command getting syntax error

    Win 10

    I want to rename a bunch of files to add a prefix. ie "aaa.url" to "win 10- aaa.url"

    I found these pages:

    Rename file extensions in bulk from command line [CMD]

    Forfiles

    the example and my version of the command

    forfiles /M *.jpg /C "cmd /c rename @file \"@fname - pic.jpg\""

    forfiles /M *.* /C "CMD /c RENAME @FILE \"WIN 10- @FILE\""

    I get this output:

    D:\Public\Favorites\@test>forfiles /M *.* /C "CMD /c RENAME @FILE \"WIN 10- @FILE\""

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    'Tutorials' is not recognized as an internal or external command,

    operable program or batch file.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    The syntax of the command is incorrect.

    As far as I can see I have the syntax OK, but obviously windows does not agree with me.

    What am I missing?
     
    Rohn007, Apr 2, 2020
    #3
  4. DennisCPA Win User

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

    Batch File Syntax: Insert %USERPROFILE% into batch file command lines

    Following batch file code lines work fine.

    Batch File that works:

    CD "C:\Users\xlmas\Documents\Visual Studio 2013\Projects\ToolsNET\bin\Release\"

    "C:\Users\xlmas\Documents\Visual Studio DOS Utilities\RegAsm64" "C:\Users\xlmas\Documents\Visual Studio 2013\Projects\ToolsNET\bin\Release\ToolsNET.dll" /UNREGISTER

    Goal:

    Want to substitute the environmental variable %USERPROFILE% for "C:\Users\xlmas" but I keep running into syntax issues. The issue seems to be related to the spaces in the Path. I have attempted the code with and without quotation marks. Either way there
    are syntax errors when invoking RegAsm64. If I include quotation marks (to preserve the folder name with spaces) in the Set commands they screw up attempting to run RegAsm64.

    Failed attempts:

    Set DLLPathEnd="\Documents\Visual Studio 2013\Projects\ToolsNET\bin\Release"

    Set DosUtilEndPath="\Documents\Visual Studio DOS Utilities"

    Set DLLFullPath=%UserProfile%%DLLPathEnd%

    CD %DLLFullPath%

    Set DosUtilFullPath=%UserProfile%%DosUtilEndPath%

    %DosUtilFullPath%\ResAsm64 %DLLFullPath%\ToolsNET.dll /UNREGISTER

    Any thoughts greatly appreciated!
     
    DennisCPA, Apr 2, 2020
    #4
Thema:

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

Loading...
  1. Syntax for Batch file &/or powershell script to run multiple commands - Similar Threads - Syntax Batch file

  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. Need Help Regarding Powershell Command in Batch Script to Mount Wim

    in Windows 10 Customization
    Need Help Regarding Powershell Command in Batch Script to Mount Wim: Please Help. I want Powershell to show Grid View as Output of Wim Indexes then when a user select one from menu & press OK it will then mount the selected wim. Get-WindowsImage -ImagePath "\install.wim" | Out-GridView -PassThru -Title 'Select Windows Image and press OK'|...
  5. run a powershell command like a batch file

    in Windows 10 Installation and Upgrade
    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...
  6. Automatically Run Batch Script

    in Windows 10 Installation and Upgrade
    Automatically Run Batch Script: Hi everyone When the windows installation is finished, automatically run batch script. How can I do that? Thanks *Wink 122531
  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--