Have you always found PowerShell and scripting intimidating, but you have always wanted to learn how to automate using PowerShell?
This course is meant for the complete non-programming beginner who wants to know about PowerShell and some cool scripting with PowerShell. We will start at the beginning, using PowerShell Cmdlets and then moving on to scripting in which those same Cmdlets can and will be used.
Have you always found PowerShell and scripting intimidating, but you have always wanted to learn how to automate using PowerShell?
This course is meant for the complete non-programming beginner who wants to know about PowerShell and some cool scripting with PowerShell. We will start at the beginning, using PowerShell Cmdlets and then moving on to scripting in which those same Cmdlets can and will be used.
This course is intended for people who don’t know how to program or script and want to learn how to not only use PowerShell one-liners in the shell, but also have always wanted to learn how to script but never thought they could.
We will go through the material step by step, starting at Cmdlets and parameters, filtering properties and moving on to scripting, using if/elsif/else statements, using arrays with foreach loops and combining it all plus much more. Everything is done step by step. No knowledge is assumed and no steps omitted and it is going to be fun, which is important to keep learning.
At the end you should know how to use PowerShell, using its Cmdlets and knowing how to do very effective PowerShell scripting .
Welcome to PowerShell from Beginner to Sheller and Scripter.
Introduction. Also don't forget to check out the bonus video!
Starting the PowerShell shell
Using the PowerShell shell
Why we already know PowerShell
What are Cmdlets ?
Using Cmdlets and parameters
What are properties ? Do not belong to Cmdlets
EXAMPLES:
Get-Service
Stop-Service
Start-Service
Looking online
Get-LocalUser
Set-LocalUser
To quote or not to quote
Using Help with Cmdlets using the Cmdlet Get-Help to get the parameters and values it needs.
Using the internet to find out about Cmdlets
Updating help with Update-Help
How do you find the right Cmdlet for the job to do ?
Is it Set-LocalUser or Disable-LocalUser for disabling a local user ?
What are modules ?
Using Get-Command
What is the PowerShell pipeline ?
EXAMPLES:
Get-Service –Name ‘spooler’ | Stop-Service
Get-Service –Name ‘spooler’ | Start-Service
Get-LocalUser –Name ‘Dave’ | Set-LocalUser –Description ‘My Lovely Account’
What is the PowerShell pipeline ?
EXAMPLES:
Get-Item -Path ’C:\Source\1.txt' (Retrieve one item)
Copy-Item -Path 'C:\Source\1.txt' -Destination 'C:\Target'
Get-Item -Path ’C:\Source\1.txt' | Copy-Item -Destination 'C:\Target'
What is the PowerShell pipeline ?
EXAMPLES:
Get-ChildItem -Path ’C:\Source' (Retrieve all items in a directory)
Get-ChildItem -Path ’C:\Source' | Copy-Item -Destination 'C:\Target'
How do we output to a text file ?
EXAMPLES:
Get-Service | Out-File –FilePath ‘c:\test\services.txt’
Look at properties again and why parameters are not properties.
Drop a word called ‘object’ on you and see how you respond
How do we format data in PowerShell ?
EXAMPLES:
Get-Service | Format-List –Property
Get-Service | Format-Table –Property
Get-Service | Format-Table –Autosize | Out-File –FilePath ‘C:\test\test.txt’
PowerShell Objects a deeper look what they are and where they come from !
How can we find out the properties and methods of an object?
EXAMPLES:
Get-Service | Get-Member
Get-LocalUser | Get-Member
How can we find out the kind of properties of an object?
EXAMPLES:
Get-Service | Get-Member
How can we find out the kind of parameters we need ?
EXAMPLES:
Get-Service
How can we find out the kind of parameters we need ?
EXAMPLES:
Get-Service
How can we get only the stuff we need based on a property of an object ?
EXAMPLES:
Get-Service | Where-Object {$PSItem.status –eq ‘running’} | Out-File –FilePath ‘C:\reports\report.txt’
How can we get only the stuff we need based on a property of an object ?
EXAMPLES:
Get-LocalUser | Where-Object {$PSItem.enabled –eq $false} | Set-LocalUser ` –Description ‘Disabled Account’
How do we select specific information ?
EXAMPLES:
Get-Service | Select-Object –First 5
Get-Service | Select-Object –Last 5
Get-Service | Select-Object –Property name,status –First 5 | Out-File –FilePath ‘C:\test\services.txt’
How can we group in alphabetical order or from high to low and vice versa?
EXAMPLES:
Get-Service | Sort-Object –Property ‘Status’
How can we output to CSV in a simple way ?
Getting it all together + some gotchas
A nice Mini Challenge to think about!
A nice Mini Challenge to think about...again!
Moving on to a script
What is a PowerShell script ?
Using and exploring the PowerShell ISE (Integrated Scripting Environment)
Running a small script
Set-ExecutionPolicy
Writing our first PowerShell Script “Hello Wonderful People!”
Variables in PowerShell
What is a variable ?
Defining a variable in PowerShell
Different types of variables in PowerShell (DataTypes) and why important ?
Example string,int,datetime and many many more.
Integer (int)
String (str or text)
Boolean (bool)
DateTime (Store Date)
Using [string]$DogType or [int]$Number to tell PowerShell what datatype you want.
Using $MyVariable.GetType() to see what kind of variable you have.
Getting data from the user using Read-Host.
Using this data in a PowerShell Script.
What are Arythmic Operators ?
+ Add, - Subtract, * Multiply, / Divide, % Mod(Remainder)
Objects 2 the return of the killer object…
Putting an object into a variable and using its properties and methods, more specifically it is an instance from a command.
EXAMPLES:
$Service = Get-Service –Name ‘spooler’
$Service | Get-Member
How to use If Statement to make decisions in your script
Creating multiple decisions in your script with If/ElseIf/Else Statement
And some gotchas
If/Elseif/Else statement.
Scripting Example : if a local user is enabled, disable it and if a local user is disabled enable it.
STEPS:
Which Cmdlets do I need ? Look at the internet to find out.
Which Parameters of Cmdlets am I going to use ?
What variables am I going to use.
Which properties of the object which is in the variable do I need and what are the possible values of the properties.
If/Elseif/Else statement. And some extra tips and tricks added continuing part 3!
Scripting Example : if a local user is enabled, disable it and if a local user is disabled enable it.
STEPS:
Which Cmdlets do I need ? Look at the internet to find out.
Which Parameters of Cmdlets am I going to use ?
What variables am I going to use.
Which properties of the object which is in the variable do I need and what are the possible values of the properties.
If/Elseif/Else statement. And let's make a sentence continuing part 4!
Scripting Example : if a local user is enabled, disable it and if a local user is disabled enable it.
STEPS:
Which Cmdlets do I need ? Look at the internet to find out.
Which Parameters of Cmdlets am I going to use ?
What variables am I going to use.
Which properties of the object which is in the variable do I need and what are the possible values of the properties.
Nested If/ElseIf/Else statement.
Continuing Nesting If/ElseIf/Else statement. (That bird doesn't have it easy)
What are comparison operators ?
What are logical operators ?
Are you ready to program the next gaming sensation ?
Explanation of what a loop is and what a While loop does
PowerShell Arrays
Indexing in an Array
Using the Foreach to loop through a PowerShell array
PowerShell Arrays with LocalUsers
Indexing in an Array with LocalUsers
Using the Foreach to loop through a PowerShell array of Local User Objects
Using a combination Foreach and If
Mmmm nothing more descriptive to add here
Creating Local Users from a simple text file
Creating Directories or files from a simple text file
Well...just in case you didn't know how
Using and exploring the Import-Csv Cmdlet
Using the Import-Csv Cmdlet to create Local Users
You will need to finish the set up lab environment to follow along, or use your own setup
Moving to Active Directory
Creating an Active Directory User with PowerShell
Since the Active Directory Cmdlets are tricky, I have added them here in the scripting part
Moving to Active Directory
Retrieving a user in Active Directory
Since the Active Directory Cmdlets are tricky, I have added them here in the scripting part
Moving to Active Directory
Set AD user properties
Since the Active Directory Cmdlets are tricky, I have added them here in the scripting part
Moving to Active Directory
Creating an Organizational Unit
Move Active Directory users from one OU to another OU
Selecting more Active Directory Users with Where-Object
Nothing more to add here, except that maybe you can do this yourself and then watch the video!
Just create a file with some names and add them to Active Directory in any OU you want !
Again, nothing more to add here, except that maybe you can do this yourself and then watch the video!
Just import a CSV file we created earlier for the Local Users!
OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.
Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.
Find this site helpful? Tell a friend about us.
We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.
Your purchases help us maintain our catalog and keep our servers humming without ads.
Thank you for supporting OpenCourser.