You need to sign up to get access!

Sign up to get full access to this course.

Sign up to access this lesson

Click here to sign up and get access to this lesson!

Saving Progress...

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.

Sign up to access the rest of this lesson

You must either log in or sign up to access this lesson.


Course Introduction

• 1min

0 / 1 lessons complete

Getting Started with Active Directory Domain Services

• 52min

0 / 6 lessons complete

Introduction to Active Directory Users & Computers

• 1hr 23min

0 / 10 lessons complete

Adding a Second Domain Controller

• 1hr 30min

0 / 7 lessons complete

Active Directory Backups

• 1hr 24min

0 / 5 lessons complete

How to Administrate Active Directory with Windows PowerShell

• 1hr 58min

0 / 7 lessons complete

Administrating AD SS (Active Directory Sites and Services)

• 1hr 3min

0 / 5 lessons complete

Active Directory Trusts

• 54min

0 / 5 lessons complete

Modifying the Active Directory Schema

• 43min

0 / 3 lessons complete

Course Conclusion

• 1min

0 / 1 lessons complete