Issues using PowerShell scripts on Windows Server 2012

We are performing some tests with server 2012, in regards to our PowerShell scripts and we’ve run into some issue that we figured out, as far as the ExecutionPolicy, but now I’m getting another issue. I’m trying to call a custom function that compiles an application switch to test the validity of its license. The issue I’m seeing is when I try to call the function, I’m getting a popup and I want to eliminate that so that it runs without any user interaction.

the popup says:

“Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning message.”

I tried to do the Unblock-File, is hasn’t worked…

These are called “problems,” not “issues.” :slight_smile:

You don’t mention what execution policy you’re at, but this is a result of that. Unblock-File won’t work in this particular instance.

What execution policy are you using?


    Scope ExecutionPolicy
    ----- ---------------

MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted

Try setting it to Bypass and see if you’re still getting the pop-up.

If I run this:

Set-ExecutionPolicy Bypass

Will that change the configuration for the server to “always” bypass any popups?

Well, let’s just TRY it once, and see what happens. If it works to suppress that one popup, I’ll explain what I think’s happening, and you can make a decision about what you want to do moving forward.

I’m waiting for the admin to come in to work and apply that for me, I’ll let you know what comes of it…

Are you running the script from a network share? I’ve encountered that specific issue before. IE sites and zones specifies that a UNC path like \(server).(tld)\ is in the “internet” zone and hence does not trust files/scripts/etc from that path by default. You could add the UNC path to the trusted sites in IE and that may work, or try using \server\share (just the server name, not the fqdn) as the UNC path and that is considered the “intranet” zone which is trusted. At least if I recall correctly that should help…

yes, the function that are being called are in a network location and they are being called as \servername\share… We’re not using the fqdn, I might try the trusted sites thing though…

That’s ultimately what I was testing with Bypass. If Bypass eliminates the pop-up, then the pop-up is because the script shows as a “remote script.” Another “fix” is to digitally sign the script - it won’t ever generate pop-ups, then.

well, I’ve gotten a little further, now it errors like this:

“Start-Process : This command cannot be run due to the error: The system cannot find the file specified.”

this start process call is in a function that is in a network share…

That’s completely unrelated to the execution policy pop-up. I suggest you start a new thread to ask about that question, and include the relevant portion of code that you’re trying to run as well as the error. It’s impossible to diagnose that based solely on an error message, unfortunately, although the error is also useful.

When you post, be clear about what code is running, where that code is located, and what you’re trying to accomplish.

Maybe it’s an idea to take a step and do some debugging on this.

You say that you’re waiting for an admin to come in to change the setting. Does this mean you’re not running PowerShell in an administrative context?

Also, are you sure there are no GPOs in place regards running of scripts?

When you got the powershell files, were they in a compressed EXE or ZIP file by any chance? If so, I’d recommend unblocking THAT file, then expanding the contents. You can get some funny results sometimes if you dont.

Check to see if the session see the file by using Test-Path against the UNC.

Check to see you can successfully map a PS Drive to the UNC path

Check to see if you can copy one or more of the files from the network location to a local folder in the session.

If you’re able to do all this, are you dot sourcing the code and then running it, running it from powershell.exe, or directly calling it?

Lastly, can we some of the code? That’s been known to help… :wink:

Yea, I was waiting on the admin, he set the executionpolicy to bypass and i no longer got the popups, now I got that error…I will try some of that debugging and open a new thread if it continues to be an issue…:slight_smile: