This document provides an agenda for a 10 hour PowerShell training course. The agenda covers PowerShell fundamentals like variables, data types, conditions, loops, cmdlets, functions, modules, and execution policy. It also covers more advanced topics like PowerShell remoting, working with Active Directory using PowerShell, and building PowerShell scripts. The document includes examples to illustrate various PowerShell concepts. The training will be delivered by Pardha Sai who works as an Automation Engineer.
1. Welcome to PowerShell Training
Name : Pardha Sai (Pardhu)
Role : Automation Engineer
Course Duration : 10 Hours
2. Agenda
• What do you know about PowerShell ?
• How Powershell help’s IT ?
• Little History of Powershell
• Variables
• Data Types
• Conditions
• Loops
• What is command let ?
• How to find Cmdlets in PowerShell ?
• 3 important Cmdlets
• What is alias ?
• What is Pipeline and use of where and select object ?
• What is PowerShell profile and how it is used ?
• What is WMI Object ?
3. Agenda
• What is PowerShell Remoting and
How we can remote ?
• What is function ?
• What is module ?
• How to find and use Modules ?
• What is RSAT ?
• Client VS Server RSAT ?
• Getting Started with AD PS Module ?
• AD Module Version History
• How to import & export CSV data in PS ?
• How to Create Bulk User’s by using CSV File ?
• How to copy a user across AD?
• What is Execution Policy ?
• How to build PowerShell Script ?
4. What do you know about
PowerShell ???
How Powershell helpful to IT Administrators ???
&
5. History of powershell
Jeffrey Snover
He is a Distinguished Engineer and the Lead Architect for
the Windows Server Division at Microsoft. He is the inventor
of Windows PowerShell, an object-based distributed
automation engine, scripting language, and command line
shell.
6. Version of PowerShell
PowerShell V1.0 PowerShell V2.0 PowerShell V3.0 PowerShell V4.0 PowerShell V5.0
• Released in November
2006.
• Supports in Windows XP
SP2,Vista,2003.
• optional component of
Windows Server 2008.
• Supports in Windows 7,2008
R2.
• Also released for Windows XP
SP3,2003 SP2 and Vista SP1.
• PowerShell Remoting
• Modules Supports
• Windows PowerShell Integrated
Scripting Environment (ISE)
• Exception Handling Supports
• APIs Supports
• New Cmdlets
• Supports in Windows 8,2012.
• Also released for win 7
SP1,2008 SP1 and 2008 R2
SP1.
• Help update (Man Pages)
• Automatic module detection
• Session connectivity
• New Cmdlets and Modules
• Supports in Windows
8.1,2012 R2
• Also released for win 7
SP1,2008 R2 SP1 and 2012
R2 SP1.
• Desired State Configuration
• New Default Execution Policy
• Enhanced debugging
• workflow PowerShell
• New Cmdlets and Modules
• Supports in Windows
10,2016 and Nano server
• Also released for win 7,8,8.1
SP1,2008 R2 SP1 and 2012
R2 SP1.
• Oneget/PowerShell get
• PowerShell class definitions
(properties, methods)
• Desired State Configuration
V2.0
• New Cmdlets and Modules
@source : Wikipedia
8. Variables
Variables store information temporarily so you can take the information
contained in a variable and process it in further steps.
PowerShell creates new variables automatically so there is no need to
specifically "declare" variables. Simply assign data to a variable. The only
thing you need to know is that variable names are always prefixed with a
"$".
You can then output the variable content by entering the variable name, or
you can merge the variable content into text strings. To do that, just make
sure the string is delimited by double-quotes. Single-quoted text will not
resolve variables.
9. • Declare Variables
• Selecting Variable Names
• Assigning and Returning Values
• Using Special Variable Cmdlets
• Default Variables
Variables
11. Data Types
There is an additional and important reason to assign data types manually because every
data type has its own set of special commands. For example, a date can be stored as text in
a String data type. And that's just exactly what PowerShell does: it's not clever enough to
automatically guess that this really is a date or time:
$date = "November 12, 2004“;$date
November 12, 2004
If you store a date as String, then you'll have no access to special date functions. Only
DateTime objects make them available. So, if you're working with date and time indicators,
it's better to store them explicitly as DateTime:
[datetime]$date = "November 12, 2004" $date
Friday, November 12, 2004 00:00:00
The output of the variable will now immediately tell you the day of the week corresponding
to the date, and also enable comprehensive date and time calculation commands. That
makes it easy, for example, to find the date 60 days later:
$date.AddDays(60)
Tuesday, January 11, 2005 00:00:00
19. What is Cmdlet ?
Cmdlet Function
Get-Location get the current directory
Set-Location change the current directory
Copy-Item copy files
Remove-Item remove a file or directory
Move-Item move a file
Rename-Item rename a file
New-Item create a new empty file or directory
A cmdlet (pronounced "command-let") is a lightweight Windows PowerShell script that performs a single function.
A command, in this context, is a specific order from a user to the computer's operating system or to an application to
perform a service, such as "Show me all my files" or "Run this program for me." Although Windows PowerShell
includes more than two hundred basic core cmdlets, administrators can also write their own cmdlets and share them.
20. How to find cmdlets in PowerShell ???
The folks at Microsoft made several design strategies when
designing PowerShell cmdlets. First is the ability to easily infer cmdlet names,
or at the very least make them easy to discover. PowerShell cmdlets are also
designed to be easy to use with standardized syntax, making them easy to
use interactively from the command line or to create powerful scripts.
PowerShell cmdlets use the Verb-Noun format
Example : Cmdlet Name Verb Noun
Get-Service Get Service
Start-Service Start Service
The verb portion of the cmdlet name indicates the action to be performed on the noun.
21. Three Important Cmdlets
If you don’t remember anything else
Get-Help : PowerShell has help info backed
right in, Just like “Man” pages in Unix
Get-Member : Since PowerShell is object
aware, This cmdlet helps explore the
methods and Properties within PowerShell
Get-Command : PowerShell’s dictionary lookup, this
will help you to find cmdlets you can use
22. What is alias ???
An alias is an alternate name or nickname for a cmdlet or for a command element, such as a function, script, file, or
executable file. You can use the alias instead of the command name in any Windows PowerShell commands.
PowerShell (Cmdlet) PowerShell (Alias) CMD.EXE / COMMAND.COM Unix shell Description
Get-ChildItem gci, dir, ls dir ls
List all files / directories in the (current)
directory
Test-Connection/ping N/A ping ping
Sends ICMP echo requests to specified
machine from the current machine, or
instructs another machine to do so
Get-Content gc, type, cat type cat Get the content of a file
Get-Command gcm help type, which, compgen List available commands
Get-Help help, man help apropos, man Help on commands
Clear-Host cls, clear cls clear Clear the screen[b]
Copy-Item cpi, copy, cp copy cp
Copy one or several files / a whole
directory tree
Move-Item mi, move, mv move mv
Move a file / a directory to a new
location
Remove-Item ri, del, erase, rmdir, rd, rm del, erase, rmdir, rd rm, rmdir Delete a file / a directory
Rename-Item rni, ren, mv ren, rename mv Rename a file / a directory
Get-Location gl, cd, pwd cd pwd
Display the current directory/present
working directory.
@source : Wikipedia
23. Pipeline
You can use pipelines to send the objects that are output by one command to be used as input to
another command for processing. And you can send the output of that command to yet another
command. The result is a very powerful command chain or "pipeline" that is comprised of a series of
simple commands.
Example : Get-Process notepad | stop-process
Get-Service | Where-Object {$_.name -Match "win"}
Get-Service | Where-Object {$_.name -Match "win"} | select Name
A pipeline is a series of commands connected by pipeline operators (|) (ASCII 124) . Each pipeline operator
sends the results of the preceding command to the next command.
26. WMI
WMI represents the insides of your computer in the form of classes. WMI provides classes for nearly everything:
processor, BIOS, memory, user accounts, services, etc.
The name of a class usually consists of the "Win32" prefix.
For example, the Win32_Service describes services.
Get-WmiObject Win32_BIOS
Get-WmiObject Win32_Process -filter 'name = "powershell.exe"‘
[wmi]"Win32_Service.Name='netman'“
Get-WmiObject win32_service | Where-Object {$_.name -eq "netman"}
Get-WmiObject win32_computersystem | gm
Get-WmiObject win32_computersystem | Select-Object domain
29. Functions
Functions are self-defined new commands consisting of general
PowerShell building blocks. They have in principle three tasks:
• Shorthand: very simple shorthand for commands and immediately
give the commands arguments to take along
• Combining: functions can make your work easier by combining
several steps
• Encapsulating and extending: small but highly complex programs
consisting of many hundreds of statements and providing entirely new
functionalities
The basic structure of a function is the same in all three instances: after
the Function statement follows the name of the function, and after that
the PowerShell code in braces.
Example : Shorthand
Function myPing
{
ping localhost
}
Example : Combining
Function NextFreeDrive
{
For ($x=67; $x -le 90; $x++)
{
$driveletter =
[char]$x + ":"
If (!(Test-Path
$driveletter))
{
$driveletter
break
}
}
}
31. Modules
A module is a package that contains Windows PowerShell commands, such
as cmdlets, providers, functions, workflows, variables, and aliases.
People who write commands can use modules to organize their commands
and share them with others. People who receive modules can add the
commands in the modules to their Windows PowerShell sessions and use
them just like the built-in commands.
BUILT-IN MODULES :
Microsoft.PowerShell.Core
Microsoft.PowerShell.Diagnostics
Microsoft.PowerShell.Host
Microsoft.PowerShell.Management
Microsoft.PowerShell.Security
Microsoft.PowerShell.Utility
Microsoft.WSMan.Management
PSScheduledJob
PSWorkflow
PSWorkflowUtility
HOW TO USE A MODULE
To use a module, perform the following tasks:
1. Install/Import the module. (This is often done for you.)
2. Find the commands that the module added.
3. Use the commands that the module added.
33. RSAT (Remote Server Administration Tools)
RSAT (Remote Server Administration Tools) is a Windows
Server component for remote management of other
computers also running that operating system. RSAT was
introduced in Windows Server 2008 R2.
RSAT allows administrators to run snap-ins and tools on a
remote computer to manage features, roles and role
services. The software includes tools for cluster-aware
updating, Group Policy management and Hyper-V
management, as well as the Best Practices Analyzer.
RSAT runs on Windows 7, Windows 8, Windows Server
2008, Windows Server 2008 R2 and Windows Server 2012.
34. Client RSAT AD VS Server RSAT AD
Client
Windows 7
Windows Server 2008 R2
Windows 8
Windows Server 2012
Windows 8.1
Windows Server 2012 R2
Server
Windows Server 2003 or 2008
AD Management Gateway Service
Windows Server 2008 R2
Windows Server 2012
Windows Server 2012 R2
Port
9389
AD
Cmdlet
Feature
Level
39. Copy-aduser
* Import the Copy-aduser Function in PowerShell Console
* Once Copy-aduser Function Loaded type below command to Execute it
Example : copy-aduser -fristName "PowerShell" -LastName "Trainer" -userLogonName
"Powershell" -SampleUserName "Pardhu" -password "Test@123"
Function is placed in
below txt file
41. Execution Policy
• Restricted
• AllSigned
• RemoteSigned
• Unrestricted
• Bypass
• Undefined
Windows PowerShell execution policies let you determine the
conditions under which Windows PowerShell loads configuration
files and runs scripts.
You can set an execution policy for the local computer, for the
current user, or for a particular session. You can also use a Group
Policy setting to set execution policy for computers and users.
Execution policies for the local computer and current user are stored
in the registry. You do not need to set execution policies in your
Windows PowerShell profile. The execution policy for a particular
session is stored only in memory and is lost when the session is
closed.
43. Thank You
To Learn Powershell you have use it more
Here are Some reference Links :
To Learn More : Use Microsoft Virtual Academy
For Practice : Use Microsoft Virtual Labs
For Cmdlets : Use TechNet
Keep up-to-date : Use https://powershell.org/
Name : Pardha Sai (Pardhu)
Role : Automation Engineer
Phone : 9885572999
Email ID : Pardhasai.Vadlamudi@in.fujitsu.com
Editor's Notes
In Slide Show mode, click the arrow to enter the PowerPoint Getting Started Center.