Search code examples
bashazureazure-devopsazure-clipowershell-core

How to run PowerShell core commands in bash script directly?


I mostly use Az CLI commands in bash scripts to manage Azure resources. Sometimes, I need to utilize the PowerShell core commands as the Az CLI versions do not exist.

I want to use both Az CLI and PS core commands in a bash shell together. I mean, I'd like to have only one bash script and execute all required commands in it.

Do you know a way to run PowerShell core commands directly in a bash script?


Solution

  • You can't do that. however you can use powershell for linux (pwsh) - https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

    e.g. from bash you can call this program and pass the command

    $ pwsh -c "write-host Hello world"
    Hello world