Windows 10: Run Multiple Commands In Powershell?

Discus and support Run Multiple Commands In Powershell? in Windows 10 Performance & Maintenance to solve the problem; 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... Discussion in 'Windows 10 Performance & Maintenance' started by EdTittel, Apr 4, 2018.

  1. EdTittel Win User

    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--
     
    EdTittel, Apr 4, 2018
    #1
  2. Geosammy Win User

    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 -Verbose
    For optimizing the (M.2 NVME) C:\ drive.

    2 .) Optimize-Volume -DriveLetter D -Verbose
    To optimize the (Mechanical HDD) D:\ drive.

    3.)Optimize-Volume -DriveLetter E -ReTrim -Verbose
    For the (SSD 850 EVO) E:\ drive.

    Is there a way to combine these 3 commands into one command.
    Which will run in Powershell.
    Without having to enter/type each of the commands separately?

    Thanks.

    :)
     
    Geosammy, May 1, 2018
    #2
  3. Zaku_Dev Win User
    RUN commands

    I just wanted to learn and allow my-self to use and troubleshoot issues on my pc better.
     
    Zaku_Dev, May 1, 2018
    #3
  4. Run Multiple Commands In Powershell?

    no run command

    OK, but if you use Win+R once, and while you have the dialogue open, you can go to the taskbar and pin the programme there. Then it will available to your mouse in the future.
     
    Alan Russell, May 1, 2018
    #4
  5. EdTittel Win User
    You can use a semicolon to string multiple PowerShell commands together onto a single line of text. Thus, for example, you could release and renew a DHCP release in PowerShell by entering

    Code: ipconfig /release; ipconfig /renew[/quote] on a single line of text. This will run the commands sequentially but will run all remaining subsequent commands, even if one command fails to execute properly. Use with caution.

    HTH,
    --Ed--
     
    EdTittel, May 1, 2018
    #5
  6. Geosammy Win User
    @EdTittel

    on a single line of text. This will run the commands sequentially but will run all remaining subsequent commands, even if one command fails to execute properly. Use with caution.

    HTH,
    --Ed--[/quote] This is the three commands I combined by using a semicolon.

    Code: Optimize-Volume -DriveLetter C -ReTrim -Verbose; Optimize-Volume -DriveLetter E -ReTrim -Verbose; Optimize-Volume -DriveLetter D -Verbose[/quote] It worked out great!
    Now I won't have to do each drive separately.
    I tried searching this, but could not find any real direct answers.
    Perhaps I typed in the wrong key words in my search.
    Nonetheless,
    thanks a bunch Mr.EdTittel *Thumbs
     
    Geosammy, May 1, 2018
    #6
  7. lx07 Win User
    Alternatively if the commands were the same you could just run one command instead of 3 and run in parallel by listing the drives separated by commas Optimize-Volume -DriveLetter C,D,E -ReTrim -Verbose Code: PS C:\Windows\system32> Optimize-Volume -DriveLetter C,D,E -ReTrim -Verbose VERBOSE: Invoking retrim on Rescue (ERun Multiple Commands In Powershell? :)... VERBOSE: Performing pass 1: VERBOSE: Invoking retrim on Windows (CRun Multiple Commands In Powershell? :)... VERBOSE: Retrim: 0% complete... VERBOSE: Invoking retrim on (DRun Multiple Commands In Powershell? :)... VERBOSE: Retrim: 0% complete... VERBOSE: Retrim: 100% complete. VERBOSE: Retrim: 0% complete... VERBOSE: Retrim: 100% complete. VERBOSE: Post Defragmentation Report: VERBOSE: Retrim: 100% complete. VERBOSE: Post Defragmentation Report: VERBOSE: Post Defragmentation Report: VERBOSE: Volume Information: VERBOSE: Volume Information: VERBOSE: Volume Information: VERBOSE: Volume size = 4.38 GB VERBOSE: Volume size = 63.90 GB VERBOSE: Volume size = 164.00 GB VERBOSE: Cluster size = 4 KB VERBOSE: Cluster size = 4 KB VERBOSE: Cluster size = 4 KB VERBOSE: Used space = 1.54 GB VERBOSE: Used space = 125.11 GB VERBOSE: Used space = 34.85 GB VERBOSE: Free space = 2.84 GB VERBOSE: Free space = 38.88 GB VERBOSE: Free space = 29.04 GB VERBOSE: Retrim: VERBOSE: Retrim: VERBOSE: Retrim: VERBOSE: Backed allocations = 4 VERBOSE: Allocations trimmed = 37 VERBOSE: Backed allocations = 164 VERBOSE: Backed allocations = 63 VERBOSE: Total space trimmed = 968.72 MB VERBOSE: Allocations trimmed = 292 VERBOSE: Allocations trimmed = 477 VERBOSE: Total space trimmed = 37.60 GB VERBOSE: Total space trimmed = 26.73 GB PS C:\Windows\system32>[/quote] Or perhaps use (again via powershell) defrag /c /h /o as this will run the correct optimization (trim/slab consolidate/defrag depending if it is SSD/VHD/HDD) for any connected volumes without demanding their names.

    This is how I do it anyway and you can see it ran retrim on SSD volumes and defragmentation of F: (which is a HDD)... Code: PS C:\Windows\system32> defrag /c /h /o Microsoft Drive Optimizer Copyright (c) Microsoft Corp. Invoking retrim on System... Retrim: 100% complete. The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 99.99 MB Free space = 73.63 MB Retrim: Total space trimmed = 0 bytes Invoking defragmentation on Dock (FRun Multiple Commands In Powershell? :)... Pre-Optimization Report: Volume Information: Volume size = 465.75 GB Free space = 142.28 GB Total fragmented space = 0% Largest free space size = 142.13 GB Note: File fragments larger than 64MB are not included in the fragmentation statistics. The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 465.75 GB Free space = 142.28 GB Total fragmented space = 0% Largest free space size = 142.13 GB Note: File fragments larger than 64MB are not included in the fragmentation statistics. Invoking retrim on (DRun Multiple Commands In Powershell? :)... The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 164.00 GB Free space = 38.88 GB Retrim: Total space trimmed = 37.60 GB Invoking retrim on Rescue (ERun Multiple Commands In Powershell? :)... Retrim: 100% complete. The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 4.38 GB Free space = 2.84 GB Retrim: Total space trimmed = 968.72 MB Invoking retrim on Windows (CRun Multiple Commands In Powershell? :)... The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 63.90 GB Free space = 29.04 GB Retrim: Total space trimmed = 26.73 GB PS C:\Windows\system32>[/quote] Many ways to do things *Smile
     
    lx07, May 1, 2018
    #7
  8. Geosammy Win User

    Run Multiple Commands In Powershell?

    @lx07

    Or perhaps use (again via powershell) defrag /c /h /o as this will run the correct optimization (trim/slab consolidate/defrag depending if it is SSD/VHD/HDD) for any connected volumes without demanding their names.

    This is how I do it anyway... Code: PS C:\Windows\system32> defrag /c /h /o Microsoft Drive Optimizer Copyright (c) Microsoft Corp. Invoking retrim on System... Retrim: 100% complete. The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 99.99 MB Free space = 73.63 MB Retrim: Total space trimmed = 0 bytes Invoking retrim on (DRun Multiple Commands In Powershell? :)... The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 164.00 GB Free space = 38.88 GB Retrim: Total space trimmed = 37.60 GB Invoking retrim on Rescue (ERun Multiple Commands In Powershell? :)... Retrim: 100% complete. The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 4.38 GB Free space = 2.84 GB Retrim: Total space trimmed = 968.72 MB Invoking retrim on Windows (CRun Multiple Commands In Powershell? :)... The operation completed successfully. Post Defragmentation Report: Volume Information: Volume size = 63.90 GB Free space = 29.04 GB Retrim: Total space trimmed = 26.73 GB PS C:\Windows\system32>[/quote] Many ways to do things *Smile[/quote] Thank you.
    That's a much simpler command line.
    *Thumbs
     
    Geosammy, May 1, 2018
    #8
Thema:

Run Multiple Commands In Powershell?

Loading...
  1. Run Multiple Commands In Powershell? - Similar Threads - Run Multiple Commands

  2. Command Prompt And PowerShell Run Automatically On Reboot

    in AntiVirus, Firewalls and System Security
    Command Prompt And PowerShell Run Automatically On Reboot: The last 3 times I've rebooted, I notice that the first thing to run is CMD.exe open window and if I do not immediately stop it, it launches I suspect command prompt lauches it PowerShell which runs a script open window and they both will close.I also suspect this is a virus...
  3. Error while running PIP3 command on powershell

    in Windows 10 Gaming
    Error while running PIP3 command on powershell: Please assist me to sort out the issue on the below screenshot.The command is 100% correct because I ran it on another computer it is working.I'm getting error that " the term pip3 is not recognized "I have seen all the differences of pip vs pip3 as well.I am wondering if i...
  4. Powershell can't run appx commands

    in Windows 10 BSOD Crashes and Debugging
    Powershell can't run appx commands: So a few windows processes are hogging up all my memory and cpu such as the gaming services which I never use I do play Minecraft java But I doubt it uses gaming services. So I wanted to get rid of those. I tried running some appx commands which were given on the forum And...
  5. Powershell can't run appx commands

    in Windows 10 Gaming
    Powershell can't run appx commands: So a few windows processes are hogging up all my memory and cpu such as the gaming services which I never use I do play Minecraft java But I doubt it uses gaming services. So I wanted to get rid of those. I tried running some appx commands which were given on the forum And...
  6. Powershell can't run appx commands

    in Windows 10 Software and Apps
    Powershell can't run appx commands: So a few windows processes are hogging up all my memory and cpu such as the gaming services which I never use I do play Minecraft java But I doubt it uses gaming services. So I wanted to get rid of those. I tried running some appx commands which were given on the forum And...
  7. Error while running PIP command on powershell

    in Windows 10 Customization
    Error while running PIP command on powershell: Please assist me to sort out the issue on the below screenshot. The command is 100% correct because I ran it on another computer it is working. [ATTACH] I am wondering if i can post powershell issues here or there is another website specific for powershell problems...
  8. 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...
  9. 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...
  10. 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...

Users found this page by searching for:

  1. run powersell multiple commands