How to run multiple commands in a powershell alias?

Member

by dedrick , in category: Third Party Scripts , 2 days ago

How to run multiple commands in a powershell alias?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by brandy , 2 days ago

@dedrick 

You can run multiple commands in a PowerShell alias by separating the commands with a semicolon. Here's an example:

1
New-Alias -Name "MyAlias" -Value "Get-Process; Get-Service"


In this example, the alias "MyAlias" is created to run two commands: "Get-Process" and "Get-Service". When you run the alias "MyAlias", both commands will be executed one after the other.


You can also create a script block with multiple commands and execute it using the alias. Here's an example:

1
New-Alias -Name "MyAlias" -Value { Get-Process; Get-Service }


In this example, the alias "MyAlias" is created to run a script block with two commands: "Get-Process" and "Get-Service". When you run the alias "MyAlias", the script block with both commands will be executed.