Enabling Script Execution for PowerShell
Full-Access Members Only
Sorry, this lesson is only available to Server Academy Full-Access members. Become a Full-Access member now and get instant access to this and many more premium courses. Click the button below and get instant access now.
Instructions
Q&A (0)
Notes (0)
Resources (0)
Saving Progress...
Resources
There are no resources for this lesson.
Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.
In this lecture, I am going to be talking to you about Windows PowerShell Script Execution.
When you create a script in PowerShell and you save it, and then you attempt to run it some of you will run into an error like the one below.
Let’s log into IPDC01 and click on the Windows icon at the bottom left and type PowerShell.
We can open either Windows PowerShell or Windows PowerShell ISE.
The first option Windows PowerShell opens a prompt similar to CMD.
If we choose the Windows PowerShell ISE it's more like a code editor.
Let’s type in a command like echo “Hello World” and press the Green Play Button at the toolbar to execute the script. We will get the output in the bottom part.
Now, if we save the script by clicking on File in the menu and selecting Save As…
We name the script Test and save it to the C:\ drive by clicking on the Save button.
Now, if we attempt to run the script by clicking on the Green Play button we are going to get the following error saying: File C:\Test.ps1 cannot be loaded because running scripts is disabled on this system.
You can try and run a command to elevate the execution policy, or set it to unrestricted, or allow all scripts to be written, but if your scripts are blocked by Group Policy none of these will work.
What we want to do is click on the Windows icon and type rsop.msc and click on the application.
It will display a window that the Resultant Set of Policy is being processed...
We are going to look for a specific PowerShell that is blocking our script execution. Expand Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell
Here we can see that Turn on Script Execution is Disabled.
Also, if you expand User Configuration > Administrative Templates > Windows Components > Windows PowerShell here we can see that it is Enabled.
Scroll down on the Explanation tab and you'll see the reason why.
So even if we Enabled it for the User Accounts it is Disabled for the Computer Accounts. In other words the scripts are not going to be able to be executed.
Now we have set this in our Domain Controller on purpose to create this error. Some of you who work in production environments where they're a little more secure this setting will be disabled, and will prevent you from running your scripts. So you’ll need to enable that for your domain computers or wherever you want to run your scripts. I will set up a member server and will restrict access to that server for Administrator groups and I will enable script execution on that server.
To fix this, I will open Group Policy and we will fix this setting.
I configured it under the Default Domain Policy. If we go back to the rsop.msc under GPO Name, we see it has been configured in the Default Domain Policy.
So, right-click on Default Domain Policy under Group Policy Management and choose Edit...
Under Computer Configuration navigate to Policies > Administrative Templates > Windows Components > Windows PowerShell
Here we can see that Turn on Script Execution is Disabled.
Double-click on it to edit and choose the Not Configured option and click OK.
Also, I am going to navigate under User Configuration > Policies > Administrative Templates > Windows Components > Windows PowerShell
Double-click on Turn on Script Execution to edit the policy.
Server Academy Members Only
Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.
On my first lab objective, I have to set the PS Script Execution Policy to Unrestricted; however, my virtual lab powershell test.ps1 works on the first try meaning that my lab’s Script Execution Policy is ALREADY Unrestricted, and when I go to the RSOP console, I could not find the Powershell component on either the Computer Configuration nor the User Configuration. Needless to say, When trying to score my first objective, it says that the Script Execution Policy is NOT set to Unrestricted.
Any help?
Hi Paul Ma
The reason why it is not showing the PowerShell component is that the policy is not set. Try enabling the policy and test the behavior of executing the ps1 script. You can follow the steps in this lesson.
If the score of the first objective fails is because the execution policy is still RemoteSigned. The first task is to be able to recognize the state of the execution policy in PowerShell and be able to change it.
Ricardo
How do you enabling the policy so you can Set PowerShell Script Execution Policy to Unrestricted? Because it is already appears to be in a unrestricted state.
Hi Linton Smith
You can execute Get-ExecutionPolicy to see it and Set-ExecutionPolicy Unrestricted.
Ricardo
Did not work for me.
Try enabling the policy under:
User Configuration\Policies\Administrative Templates\Windows Components\Windows PowerShell\Turn on Script Execution
At minutes 03:58, the instructor said “we are going to open group policy”, and I saw the group policy was already open, without being told how to open it. So I had to google to know how to open it.
Hi Adi Nugroho
We are sorry fo it, it was already opened. You can open Group Policy from Server Manager > Tools > Group Policy Management.
Ricardo
Ok, thank you 😊
Mr. Ricardo sir the links for tech issues and billing do not work. It directs me to a page that says “The link you followed has expired” I’ve been trying for the past week to contact someone by these means. Can you please help. Thank you!
Hi Tyneshia Mack
Please email support@serveracademy.com
Can you please copy-paste the links here? I did check and I can’t seem to find those links. From which page do you see those links?
I run rsop.msc but I don’t see what you’re seeing.
please find the image attached
Hi Arash Sabetghadam,
The policy is not enabled and might not show as on the video.
Try enabling the policy located under and try again with rsop.msc:
User Configuration\Policies\Administrative Templates\Windows Components\Windows PowerShell\Turn on Script Execution
Ricardo