Some PowerShell commands or cmdlets – Part 8 – Out-File, Providers and Drives

PoSh Facts:

PowerShell is a .NET application, so you won’t be able to do anything that you are not allowed to do

So this makes PoSh as limited or as powerful as the account in which you are logged in

Using Out-file (to capture output and save it into afile)

get-process | format-table name, id -Autosize |out-file -filepath c:\posh\sortprocess.txt

Export-CSV – Exporting output into a CSV file format
gps | select name, id | Export-Csv -Path C:\posh\sortproc.csv

gps is the alias for get-process; Exporting the file in CSV format allows you to open the file with Excel

gps | select name, id | Export-Csv -Path C:\posh\sortproc.csv -NoTypeInformation
Export-CliXML – Exporting to a XML file format
gps | Export-Clixml -Path c:\posh\proc.xml

Storing the output into a variable

$a = Import-Clixml -Path c:\posh\proc.xml   ($a now contains data)

Displaying the variable on the screen

Sorting the output
$a | sort name
$a | sort name -descending

The idea behind Providers is that it uses exactly the same tools and methodology to access
different types of data; e.g. You can look at the registry the same way you can look at the file system
You can find information about system variables the same way you can find information about certificates, and so on
The comdlets that allows us to work with providers usually have the names of items such as Get-Item, Get-ChildItem, Set-Item. The word “item” in general tems can be anything: a file, a folder, a certificate, a variable, an alias, a funtion, an AD user, a blocked OU. So the concept of provider is extensible, that means that other people, other groups, other organizations can build upon this idea of providers. Because we can build upon this idea of providers, then we we can add additional information to these.
These ideas of providers are exposed as drives. Example: you can issue the cmdlet Get-PSDrive to give us a listing of PowerShell Drives
Lists all available providers
Lists all drives; Note in PoSh, a drive is not only the regular disk drives we are familiar with (C, D, E, F, etc) but other component, such as: variables, registry keys (HKLM HKCU), Aliases used in PoSh, Functions, certificates and WSMan (Web Services Management object, are also called drives

Changes location of the drives, e.g.:
Set-Location Variable:
Set-Location Alias:
Set-Location c:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: