PowerShell - Working With Providers-F22
PowerShell - Working With Providers-F22
Objectives
In this lab, you will learn how to work with Windows PowerShell providers.
Windows PowerShell providers enable you to access data that would not otherwise be easily
accessible at the command line. The data that a provider exposes appears in a drive, much like
a hard drive, and is presented in a consistent format that resembles the file system. You can use
any of the built-in cmdlets that the provider supports to manage the data in the provider drive,
in addition to custom cmdlets that are designed especially for the data. By default, Windows
PowerShell includes several providers that allow you to access common data stores in
Windows, such as the file system, registry, and certificate store.
Steps:
1. To start, turn on Windows computer (either PC/laptop host or VM), and open Windows
PowerShell command window.
2. List the available providers and the drives which make use of these providers. You will
also create a new drive using the registry provider.
b. To display a list of the available providers, type the following command, and then
press ENTER. Do you have the same output? Yes.
Get-PSProvider
Note down the difference based on your outputs.
3. To display a list of the available drives, type the following command, and then press
ENTER. Do you have the same output? ____ .
Get-PSDrive
Note down the difference based on your outputs.
I have two extra drives out f which one is empty and the other(F) is having usage of 3.31 GB.
How to find the PSdrive key word related cmdlets? We can use the command Get-
Command *PSDrive*.
4. Run regedit.msc. Use the Registry Editor window as reference. In next steps, you will
create new PSDrives based on Registry.
To create a new drive for the HKEY_CLASSES_ROOT hive in the registry using the Registry
provider, type the following command, and then press ENTER.
5. To browse to the newly created drive, called HKCS, as if you were working with a drive in
the file system, type the following commands, pressing ENTER after each one.
cd HKCS:
dir .ht*
Verify the output by checking the Registry Editor window HKEY_CLASSES_ROOT hive.
NOTE: This will set the current location to the newly created HKCS drive, and then
display the list of registry entries that match the filter expression. IMPORTANT: The
trailing colon (:) after the drive name indicates a drive change which is different from a
folder change. The colon is necessary; otherwise, Windows PowerShell will display an
error.
To change the current folder to another folder inside the HKCS drive, and then list its
contents, type the following commands, pressing ENTER after each line.
cd .html
dir
Do you see the listing of a key of the registry as if it were a folder in the file system? Yes.
6. Now, create a new drive for the HKEY_CURRENT_CONFIG hive in the registry and verify it.
Cd hkcc:
Dir
Verify the output by checking the Registry Editor window HKEY_CURRENT_CONFIG hive.
List and test your command (one line) to end the regedit processes.
7. Now get into HKCU: drive, and change Notepad item properties by the following.
Cd hkcu:
Do you see Notepad? YEs. (In case you don’t have it in the output, skip this step and move
to Step 8.)
Get-ItemProperty notepad
iWindowPosX 662
iWindowPosY 325
IWindowPosDX 529
iWindowPosDY 470
lfItalic 0
lfUnderline 0
Run the notepad program again, and verify the above property change. Do you see thee
customized Notepad window frame? Yes.
Key in any text in the notepad page, notice that Italic and Underline are not set.
Again, run the notepad program, and verify the above property change. Do you see the
newly customized Notepad window frame? Yes.
Verify the change by the following cmdlet.
Get-ItemProperty notepad
Get-ItemProperty notepad
Key in any text in the new notepad page, notice that Italic and Underline are now set.
Key in the following command to verify all the open Notepad processes.
List and test your command (one line) to end of the Notepad processes.
Reset Italic and Underline as default before you proceed to the next step.
Cd alias:
Dir or get-childitem
Issue Dir or get-childitem, do you see the new alias in this PSdrive? _____ .
Verify by command “get-alias pro”, and also type in pro, do you see the same output same
as the cmdlet “get-process” output? Yes it seems same.
Remove-item pro
Del ser
9. Now, work with Env: PSdrive. Note down the outputs of related command lines.
We use PowerShell to manipulate the System variables, this is an alternative to using the
Windows GUI and navigating to the Control Panel, System and Advanced System Settings.
Cd env:
Dir or get-childitem
Note: The environment settings in this drive will be used frequently in other labs.
Note: You need that $ dollar sign. Plain Env:name does not work here.
$env:PSModulePath
10. Now, work with Variable: PSdrive. Note down the outputs of related command lines.
cd variable:
dir
There are group of default variables predefined in PowerShell. Read the variable list
carefully, and figure out the value of the following variables:
Name Value
Home C:\Users\aneen
MaximumAliasCount 4096
PSEdition Desktop
ErrorActionPreference Continue
True True
$tvar
$adds
$gbc
variable: PSdrives, do you see those newly created items still available? Yes.
Check the two new PSdrives HKCC and HKCS (by get-psdrive). Are they still available? No.
11. Now, work with filesystem PSdrive. Create and verify the new file and directory by
PowerShell commands.
Cd c:
new-item -type File -name test1.txt -value "Here is the test file1."
12. Now, work with Certificate PSprovider. Based on the above steps, answer and test the
following. (Test before reading the Hints at the end of this file.)
Get into CurrentUser\Root directory, how many certificate items are there? 65.
(dir c*).getpublickeystring()
Explain what the above command does? The above mentioned command retrieves the
public key string for all certificates that match the wildcard pattern c*. It calls the
GetPublicKeyString() method on each certificate, which returns the public key of the
certificate in a readable format.
Note: The certificate settings in this drive will be used frequently in security tasks.
13. Free practice on Alias:, Env: and Variable: PSdrives. Make notes.
Summary
In this lab, you have learned how to work with different Windows PowerShell providers, and
how to add new items and change items properties.