0%

0/1 Lessons

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 27min

0 / 10 lessons complete

Adding a Second Domain Controller

• 1hr 31min

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

• 2min

0 / 1 lessons complete

Enabling Script Execution for PowerShell

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.

Create note

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.

4.3 3 votes
Lesson Rating
Subscribe
Notify of
profile avatar
13 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

profile avatar
Paul Ma(@paulm)
Member
2 years ago

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?

profile avatar
Ricardo P(@ricardop)
Admin
Reply to  Paul Ma
2 years ago

Hi profile avatar 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

profile avatar
lintons(@lintons)
Member
2 years ago

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.

Last edited 2 years ago by Linton Smith
profile avatar
Ricardo P(@ricardop)
Admin
Reply to  lintons
2 years ago

Hi profile avatar Linton Smith

You can execute Get-ExecutionPolicy to see it and Set-ExecutionPolicy Unrestricted.

Ricardo

profile avatar
lintons(@lintons)
Member
Reply to  Ricardo P
2 years ago

Did not work for me.

profile avatar
Ricardo P(@ricardop)
Admin
Reply to  lintons
2 years ago

Try enabling the policy under:

User Configuration\Policies\Administrative Templates\Windows Components\Windows PowerShell\Turn on Script Execution

profile avatar
Adi Nugroho(@adin)
Member
1 year ago

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.

profile avatar
Ricardo P(@ricardop)
Admin
Reply to  Adi Nugroho
1 year ago

Hi profile avatar Adi Nugroho

We are sorry fo it, it was already opened. You can open Group Policy from Server Manager > Tools > Group Policy Management.

Ricardo

profile avatar
Adi Nugroho(@adin)
Member
Reply to  Ricardo P
1 year ago

Ok, thank you  😊 

profile avatar
tyneshiam(@tyneshiam)
Member
1 year ago

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!

profile avatar
Ricardo P(@ricardop)
Admin
Reply to  tyneshiam
1 year ago

Hi profile avatar 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?

profile avatar
arashs(@arashs)
Member
10 months ago

I run rsop.msc but I don’t see what you’re seeing.
please find the image attached

Screenshot-2024-01-21-081909
profile avatar
Ricardo P(@ricardop)
Admin
Reply to  arashs
10 months ago

Hi profile avatar 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