Flylib.com

Books Software

 
 
 

Chapter 2 Quick Reference


Chapter 2 Quick Reference

Open table as spreadsheet

To

Do This

Produce a list of all the files in a folder

Use the Get-ChildItem cmdlet and supply a value for the folder

Produce a list of all the files in a folder and in the subfolders

Use the Get-ChildItem cmdlet, supply a value for the folder, and specify the recurse argument

Produce a wide output of the results of a previous cmdlet

Use the appropriate cmdlet and pipe the resulting object to the Format-Wide cmdlet

Produce a listing of all the methods available from the Get-ChildItem cmdlet

Use the cmdlet and pipe the results into the Get-Member cmdlet. Use the -membertype argument and supply the Noun method

Produce a popup box

Create an instance of the wshShell object by using the New-Object cmdlet. Use the Popup method

Retrieve the currently logged-on user name

Create an instance of the wshNetwork object by using the New-Object cmdlet. Query the username property

Retrieve a listing of all currently mapped drives

Create an instance of the wshNetwork object by using the New-Object cmdlet. Use the EnumNetworkDrives method



Chapter 3: Leveraging PowerShell Providers

image from book  Download CD Content

Overview

After completing this chapter, you will be able to:

  • Understand the role of providers in Windows PowerShell

  • Use the Get-PSProvider cmdlet

  • Use the Get-PSDrive cmdlet

  • Use the Get-Item cmdlet

  • Use the Set-Location cmdlet

  • Use the file system model to access data from each of the built-in providers

Windows PowerShell provides a consistent way to access information external to the shell environment. To do this, it uses providers. These providers are actually .NET programs that hide all the ugly details to provide an easy way to access information. The beautiful thing about the way the provider model works is that all the different sources of information are accessed in exactly the same manner. This chapter demonstrates how to leverage the PowerShell providers. All the scripts mentioned in this chapter can be found in the corresponding scripts folder on the CD.



Identifying the Providers

By identifying the providers installed with Windows PowerShell, we can begin to understand the capabilities intrinsic to a default installation. Providers expose information contained in different data stores by using a drive and file system analogy. An example of this is obtaining a listing of registry keys-to do this, you would connect to the registry “drive” and use the Get-ChildItem cmdlet, which is exactly the same method you would use to obtain a listing of files on the hard drive. The only difference is the specific name associated with each drive. Providers can be created by anyone familiar with Windows .NET programming. When a new provider is created, it is called a snap-in . A snap-in is a dynamic link library ( dll) file that must be installed into Windows PowerShell. After a snap-in has been installed, it cannot be un-installed-however, the snap-in can be removed from the current Windows PowerShell console.

Just the Steps 

To obtain a listing of all the providers, use the Get-PSProvider cmdlet. Example: get-psprovider. This command produces the following list on a default installation of the Windows PowerShell:

Name Capabilities Drives ---- ------------ ------ Alias ShouldProcess {Alias} Environment ShouldProcess {Env} FileSystem Filter, ShouldProcess {C, D, E, F...} Function ShouldProcess {Function} Registry ShouldProcess {HKLM, HKCU} Variable ShouldProcess {Variable} Certificate ShouldProcess {cert}