Create central repository for all PowerShell scripts and execute remotely

Let’s say that you have created hundreds of scripts and want to keep a central repository of all of them. That’s fine but normally to run a script, you run it locally. And to do that, you download the file and place it on local server and then run it. This is fine. However, one fine day you update the script with certain new commands and then you need to find all the instances of that scripts and update them too.

By using certain commands, you can directly run the script located on a web server. For this, you need to just change the execution policy to RemoteSigned. To do this, run the command:

Set-SPExecutionPolicy -ExecutionPolicy RemoteSigned -Confirm:$false

You can also set the execution policy to run at lower security levels such as unrestricted as well. Now to run the script, just get the url for script and run the below command:

iwr https://mypowershell.metavrse.com/demo1.ps1 -UseBasicParsing | iex

Or you can also use this version in PowerShell v3 or higher:

iwr https://mypowershell.metavrse.com/demo1.ps1 -UseBasicParsing | iex

So, next time, you only need to update and maintain your scripts at only place. Other servers, where you need to run the script can be set to download and run the scripts at execution time itself. This ensures that they always run the latest iteration of scripts.

Happy Automation !!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s