Configuring your systems and create a powershell script that can just be executed accross windows

So I needed a cross platform scripting language. I could have chosen bash and just used WSL but I prefer powershell over any other scripting language. Thank fully, Microsoft introduced Powershell core that's cross platform.

The first thing I had to do was install powershell core on all my boxes. I follows the instructions from powershell core's github page. To install it on Windows, Mac OSx, and Raspbian. After i got these install the powershell scripts would just run on windows. But on OSx or Linux you need to add pwsh before calling the script. But that can be easier.

First you need to put a symbolic link to pwsh in a common place on your Unix based systems. I chose /usr/local/bin/pwsh because on OSx I was unable to place it at /bin/pwsh. Now edit your powershell script and add #!/usr/local/bin/pwsh as the very first line in your script. We have to make it so the script is executable run chmod +x <script>.ps1. You can now execute your script by calling it like ./<script>.ps1. Now if your developing your script on windows and using git for source control you can add this property by running this git command git update-index --chmod=+x <script>.ps1. You'll need to commit this change and sync it but now on your unix machines you can just run ./<script>.ps1 after you have updated the file from source control.

Comments

Popular posts from this blog

How to authenticate docker to Azure Container registry

SXA and how I dealt with css/sass serialization conflicts

Kubernetes cluster on single board computers