Module 2 (1)
Module 2 (1)
Windows PowerShell providers provide access to data and components that would not
otherwise be easily accessible at the command line. The data is presented in a consistent
format that resembles a file system drive. Windows PowerShell providers are Microsoft .NET
Framework-based programs that make the data in a specialised data store available in
Windows PowerShell so that you can view and manage it. The data that a provider exposes
appears in a drive, and you access the data in a path like you would on a hard disk drive. You
can use any of the built-in cmdlets that the provider supports to manage the data in the
provider drive. And, you can use custom cmdlets that are designed especially for the data.
The providers can also add dynamic parameters to the built-in cmdlets.
PowerShell Providers allow you to navigate and manipulate data beyond just the file system.
Examples include:
These are parameters that are available only when you use the cmdlet with the provider data.
1. Built-in providers
Windows PowerShell includes a set of built-in providers that you can use to access the
different types of data stores. You can also create your own Windows PowerShell providers,
and you can install providers that others develop. To list the providers that are available in
your session, do as:
Get-PSProvider
The Windows PowerShell providers create some drives for you, such as the file
system drives (including C: and D:), the registry drives (HKCU: and HKLM:), and
the certificate drive (Cert:), and you can create your own Windows PowerShell.
These drives are very useful, but they are available only within Windows PowerShell.
You cannot access them by using other Windows tools, such as File Explorer or
Cmd.exe.
Get-PSDrive
Working with PSDrives File system drives are a subset of the Windows PowerShell.
You can identify the file system drives by the Filesystem entry in the Provider
column. To see the syntax of the Get- PSDrive cmdlet, type a Get-Command
command with the Syntax parameter:
The PSProvider parameter lets you display only the Windows PowerShell that are
supported by a particular provider. For example, to display only the Windows
PowerShell that are supported by the Windows PowerShell FileSystem provider, type
a Get- PSDrive command with the PSProvider parameter and the FileSystem value:
To view the Windows PowerShell that represent registry hives, use the PSProvider
parameter to display only the Windows PowerShell that are supported by the
Windows PowerShell Registry provider:
a. Navigating Directories
o Use Get-Location or pwd
o Use Set-Location or cd
Example-
iv. Copy a file to the specified directory and rename the file
Get-ItemProperty C:\Windows
ii. Get the properties of a specific file
Example-
i. Sorting
o Use Sort-Object
VARIABLES
Variables in Windows PowerShell (and all other scripting and programming languages) let
you store the output of something so that you can use it later.
• A variable name starts with a dollar sign ($) and can be followed by nearly any character.
• If that command generates simple data (such as a number or string), then the variable
contains simple data.
• If the command generates rich data (such as the objects that represent system processes
from the Get Process cmdlet), then the variable contains that list of rich data.
• If the command (such as a traditional executable) generates plain text (such as the output of
traditional executable), then the variable contains plain text.
In addition to variables that you create, Windows PowerShell automatically defines several
variables that represent things such as the location of your profile file, the process ID of
Windows PowerShell, and more.
1. $result=2+2
$result
2. $processes=get-process
$processes.count
You can access this information later, or even pass it down the pipeline as though it
were the output of the original command:
$processes | Where-Object { $_.ID -eq 0 }
You want to use an environment variable (such as the system path or the current user’s name)
in your script or interactive session.
1. To list all environment variables, list the children of the env drive:
Get-ChildItem env:
2. To get an environment variable using a more concise syntax, precede its name with
$env:
$env:variablename
3. To get an environment variable using its provider path, supply env: or Environment::
to the Get-ChildItem cmdlet:
Get-ChildItem env:variablename
Get-ChildItem Environment::variablename
The “Windows10” at the start of next line indicates your server is succesfully connected to
your client.