Administration and Automation with Windows PowerShell

0%

0/1 Lessons

Course Introduction

• 5min

0 / 2 lessons complete

Getting Started with Windows PowerShell

• 42min

0 / 7 lessons complete

Getting Help and Finding Commands

• 39min

0 / 6 lessons complete

PowerShell Command Syntax

• 33min

0 / 5 lessons complete

PowerShell Objects and Properties

• 35min

0 / 6 lessons complete

The PowerShell Pipeline

• 24min

0 / 2 lessons complete

PowerShell Providers

• 30min

0 / 5 lessons complete

PowerShell Arrays and Variables

• 28min

0 / 4 lessons complete

PowerShell Loops

• 19min

0 / 3 lessons complete

PowerShell Conditional Statements

• 11min

0 / 1 lessons complete

On Premises Lab Setup

• 36min

0 / 8 lessons complete

Basic Domain Administration with Windows PowerShell

• 2hr 27min

0 / 10 lessons complete

Send Emails with PowerShell

• 22min

0 / 2 lessons complete

PowerShell Desired State Configuration (DSC) Basics

• 1hr 48min

0 / 6 lessons complete

Course Conclusion

• 1min

0 / 1 lessons complete

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 show you how to create scheduled tasks to run your PowerShell scripts at a specific time on a general basis or just one time whatever the case might be.

So, what we are going to do is we are going to create a simple script that is going to add data to a text file and we are going to call the script to run every minute so that it gives us a good example how to create the scheduled tasks, how to write the scripts, and how to get them to execute.

So, the first thing we are going to do is open the PowerShell editor by hitting Start in the bottom left corner. 

Now, I am going to type in powershell, and we are going to run the PowerShell Intelligent Scripting Environment or PowerShell ISE.

Once this loads we can begin writing the script.

We are going to do a simple single-line command that is going to add some text followed by the date. Let’s start with the following and press Play.

$date = date

$content = “This is some cool content $date”

In the bottom pane if we type:

echo $content

This is the result we are going to get each time.

Now, what we need to do is continue editing adding:

$date = date

$content = “This is some cool content $date”

Add-Content C:\Scripts\Content.txt “$content”

exit

Click File > Save to save the script.

And, we are going to This PC > C:\ > and create a new folder called Scripts and name it AddContent.ps1. Click on Save.

Now, if we navigate to the C:\Scripts folder and run the script we should have a new text file called Content.txt

If we open this text file we can see the following:

If we execute the PowerShell script it should add another line. And, we can see the time difference when it was executed.

What I am going to do now is delete the Content.txt and close PowerShell ISE.

Now that we have the script created we need to create a scheduled task to call the script to run every minute or so.

I am going to do that by going to Server Manager > Tools > Task Scheduler

Left-click on the Task Scheduler Library and select Create Task…

In the Name type AddContent trying to keep the naming consistent with what we are doing. Next, in the Description add This adds some content to a txt file.

The next thing we want to do is Change the User or Group, or the user that is running the script. In the search box type Administrator and click on Check Name and select the user account Administrator. Generally, you would want to create a special user account for when you are making scheduled tasks, you generally don’t want to use the Administrator account, and more than that you don’t want to use your own user account.

If I were to set a scheduled task for something like Windows Backup and my user account got locked out because I typed in the wrong password too many times then all the scheduled tasks are going to fail because that user account is locked out. 

So, it's generally important that you create a new user account that will have the least amount of privileges necessary for it to complete the running of the script or the operation of the script.

Now, I am using the Administrator account because I don’t want to go through all the work and the hassle of creating a new user account for this simple demonstration, but just keep that in mind for the future.

Sign up to access the rest of this lesson

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

Saving Progress...

0 0 votes
Lesson Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments