Working with PSProviders and PSDrives

Working with PSProviders and PSDrives

1. PSProviders:

PSProviders help us in accessing & manipulating data collection. Example of data collection here can be the file system on your machine; another example can be Registry on your machine. In short, think of the psproviders or simply providers as data stores.

Powershell command ‘get-psprovider’ lists different kinds of providers on powershell console as shown below:

2. PSDrive

PSDrive or PowerShell Drive is used to access the data provided by PSProviders. They are nothing but a data store location that can be accessed like file system drive in powershell. Powershell cmdlet ‘get-psdrive’ is used to list the drives on the system as shown below:

File System drives, Registry drives are the drives created by powershell providers. You can think of PSDrives as a means to access data stores like Registry, Active Directory and use different cmdlets on them according to need to obtain desired results.

You can create a new psdrive by using New-PSDrive cmdlet as shown in screenshot below:

As shown in the screenshot above, -name, -PSProvider & -Root are the mandatory parameters for New-PSDrive command. â€"Name is used to give name to new drive being created, -PSProvider is used to specify type of powershell provider for the drive & -Root is used to specify the location to which newly created drive would be mapped.

You can create temporary as well as persistent drives with the help of New-PSDrive command.

Temporary drives are specific to a powershell session and can’t be viewed in file explorer whereas persistent drives can be viewed using file explorer.

Below are the other optional parameters of New-PSDrive command:







New-Item Cmdlet :

New-Item cmdlet is used to create a new item. Type of the new item being created is based on the location where the item is created. For example, in a file system, you can use New-Item to create files & folders as shown in screenshot below:

Here, we have created 2 folders, first Examples and second TestFolder inside the Examples folder.

As shown in screenshot above, we are using New-Item to create a new file at given path.

You can use ‘-Force’ parameter in New-Item cmdlet in order to overwrite the existing file while creating new file. Refer screenshot below where we are overwriting already existing ‘test.txt’ file:

Below is the list of parameters of New-Item cmdlet:

-Path: location where new item is to be created.

-ItemType: Type of item to be created (e.g. File, Directory etc).

-Value: Used to specify value for new item.

-Force: Used to create an item which overwrites existing item.

-Credential: Used to specify an user account having permission to perform this operation.

-WhatIf: Shows what would happen if this cmdlet is executed.

-Confirm: Prompts for confirmation before running the cmdlet.

-UseTransaction: Includes the cmdlet execution in an ongoing transaction.