Friday, May 29, 2015

#75 : How to run Powershell scripts from network location (UNC Path)?

In most of the cases, people ask questions if they can run the Powershell scripts from network location which is shared on multiple machines.

At first sight,  I would not suggest to do it as this is not recommended to run unsigned scripts, but requirement is always a requirement and I have seen people debating in a long mail chain when I say that something is not possible. Sometimes whole group is fighting with me one after another and using google search and all options to make me accept. Believe me, I don't believe in too much argument on any topic, but still I don't like to accept something which cannot be done or something which cannot be done perfectly.

I believe in correct usage of any technology, arguments and debates are other areas are not my areas of expertise. Anyways, for those who have been forced to do something and for those who has to do something because it has to be done.

You can use -ExecutionPolicy "Bypass" in the command line. Something like this :

For example, if you have script located at abc server's c:\abc.ps1, you can run statement like this:
Powershell.exe -ExecutionPolicy bypass \\abc\c$\abc.ps1

This will not ask any questions or input. Keep all such shared script at central location, create a share or map a drive, do whatever suits your environment.

Hope, you liked this article. Please do sent your suggestions and advises.

 

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...