logo
down
shadow

How can I make a macro to run a few PowerShell commands one after the other?


How can I make a macro to run a few PowerShell commands one after the other?

By : CakeFace
Date : November 22 2020, 03:03 PM
I wish this helpful for you You need to create a PowerShell script file. Basically the same as a batch file, but with a .ps1 extension.
code :


Share : facebook icon twitter icon
How to make a "macro" to automate some bash commands in OS X Terminal?

How to make a "macro" to automate some bash commands in OS X Terminal?


By : C.Sung
Date : March 29 2020, 07:55 AM
around this issue The name generally used in this context (a macro in bash) is shell script. To automate the commands from your post you would need to create a file with a name like 'myscript.sh' with the following contents:
code :
#!/bin/bash
cd ~/Documents/College/F13/CS362/lab3/os-lab-3
hg pull
hg update
chmod +x myscript.sh 
./myscript.sh
How to efficiently make multiple -replace commands in powershell

How to efficiently make multiple -replace commands in powershell


By : Deathcalibur
Date : March 29 2020, 07:55 AM
will be helpful for those in need Action the replaces in one go and you only need to use Get/Set-Content once:
code :
(Get-Content hvor_har_vi_vaeret_i_aar.html) -replace '"','"' -replace 'ae','æ' -replace 'o/','ø' -replace 'aa', 'å' | Set-Content hvor_har_vi_vaeret_i_aar.html
(Get-Content hvor_har_vi_vaeret_i_aar.html) `
    -replace '"','"' `
    -replace 'ae','æ' `
    -replace 'o/','ø' `
    -replace 'aa', 'å' |
    Set-Content hvor_har_vi_vaeret_i_aar.html
Trying to make a function with multiple commands into a single alias in powershell?

Trying to make a function with multiple commands into a single alias in powershell?


By : Chris LJ
Date : March 29 2020, 07:55 AM
I hope this helps . This issue you are having is trying to put a array in the new-item -name field
code :
New-Item -Path "C:\Users\Admininistrators\Sheridan\" -ItemType "directory" -Name "SYST23551", "Notes"
function CSheridanStruct {
    New-Item -Path "C:\Users\Admininistrator\" -Name "Sheridan" -ItemType "directory"
    New-Item -Path "C:\Users\Admininistrator\Sheridan" -Name "SYST23551" -ItemType "directory"
    New-Item -Path "C:\Users\Admininistrator\Sheridan" -Name "Notes" -ItemType "directory"
}

Set-Alias Sheridan CSheridanStruct

Sheridan
Wait for multiple simultaneous powershell commands in other sessions to finish before running next commands

Wait for multiple simultaneous powershell commands in other sessions to finish before running next commands


By : Dan Welder
Date : March 29 2020, 07:55 AM
With these it helps You are indeed looking for Powershell background jobs, as Lee Daily advises.
However, jobs are heavy-handed, because each job runs in its own process, which introduces significant overhead.
code :
$startedAt = [datetime]::UtcNow

# Define the commands to run as [thread] jobs.
$commands = { $n = 2; Start-Sleep $n; "I ran for $n secs." }, 
            { $n = 3; Start-Sleep $n; "I ran for $n secs." }, 
            { $n = 10; Start-Sleep $n; "I ran for $n secs." }

# Start the (thread) jobs.
# You could use `Start-Job` here, but that would be more resource-intensive
# and make the script run considerably longer.
$jobs = $commands | Foreach-Object { Start-ThreadJob $_ }

# Wait until all jobs have completed, passing their output through as it
# is received, and automatically clean up afterwards.
$jobs | Receive-Job -Wait -AutoRemoveJob


"All jobs completed. Total runtime in secs.: $(([datetime]::UtcNow - $startedAt).TotalSeconds)"
I ran for 2 secs.
I ran for 3 secs.
I ran for 10 secs.
All jobs completed. Total runtime in secs.: 10.2504931
All jobs completed. Total runtime in secs.: 18.7502717
$startedAt = [datetime]::UtcNow

$commands = { $n = 1; Start-Sleep $n; "I ran for $n secs." }, 
            { $n = 2; Start-Sleep $n; "I ran for $n secs." }, 
            { $n = 3; Start-Sleep $n; "I ran for $n secs." }

$jobs = $commands | Foreach-Object { Start-ThreadJob $_ }

# Wait until all jobs have completed.
$null = Wait-Job $jobs

# Collect the output individually for each job and print it.
foreach ($job in $jobs) {
  "`n--- Output from {$($job.Command)}:"
  Receive-Job $job
} 

"`nAll jobs completed. Total runtime in secs.: $('{0:N2}' -f ([datetime]::UtcNow - $startedAt).TotalSeconds)"

--- Output from { $n = 1; Start-Sleep $n; "I ran for $n secs." }:
I ran for 1 secs.

--- Output from { $n = 2; Start-Sleep $n; "I ran for $n secs." }:
I ran for 2 secs.

--- Output from { $n = 3; Start-Sleep $n; "I ran for $n secs." }:
I ran for 3 secs.

All jobs completed. Total runtime in secs.: 3.09
$startedAt = [datetime]::UtcNow

# Define the commands - of necessity - as *strings*.
# Note the unexpected need to escape the embedded " chars. as \"
$commands = '$n = 1; Start-Sleep $n; \"I ran for $n secs.\"',
            '$n = 2; Start-Sleep $n; \"I ran for $n secs.\"',
            '$n = 3; Start-Sleep $n; \"I ran for $n secs.\"'

# Use `Start-Process` to launch the commands asynchronously,
# in a new window each (Windows only).
# `-PassThru` passes an object representing the newly created process through.
$procs = $commands | ForEach-Object { Start-Process -PassThru powershell -Args '-c', $_ }

# Wait for all processes to exit.
$procs.WaitForExit()


"`nAll processes completed. Total runtime in secs.: $('{0:N2}' -f ([datetime]::UtcNow - $startedAt).TotalSeconds)"
Git Bash does not work for npm, node, ng commands but all these commands works in powershell windows 10

Git Bash does not work for npm, node, ng commands but all these commands works in powershell windows 10


By : user3575189
Date : March 29 2020, 07:55 AM
seems to work fine Solution:
After going through numerous solution listed on different forums, re-installing Nodejs/Git Bash cmd, tinkering PATHS.. no luck.
Related Posts Related Posts :
  • Java Version in a batch file
  • cURL in power shell windows 8.1: "A drive with the name 'localhost' does not exist"
  • Add a domain user into a local group when the domain is not available
  • windows 7 bat file leaves out parts of the command
  • psql "more is not recognized" error
  • Bundler error when executing berks command from a rake task on windows
  • Echo first three characters of filenames in CMD Windows
  • yii2 composer.phar update is not working
  • Generate memory dump for a windows service that stops unexpectedly
  • send and receive via Serial port Windows
  • Sending data over ethernet from a Raspberry Pi to a c# program on a windows PC
  • Windows driver installation failure after signing and verifying with signtool using cross signed certificates using SHA-
  • Is there any way to make a First Person Shooter input in Windows 8.1?
  • Perl: Check if string is valid directory, case SENSITIVE
  • How to add a program (in this case gmsh) to the PATH
  • Command-line to show a file's properties?
  • ErrorDocument in httpd.conf not working
  • Windows Task Scheduler - specify time window, but only fire once
  • How to delete the mistakenly case-changed renamed tag in github?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org