Prof. Powershell

PowerShell OverDrive

Get to the good stuff with the Get-PSDrive cmdlet.

I know that in the past I've discussed PSDrives in Windows PowerShell. These are special adapters that take other hierarchical systems, such as the registry, and present them as a drive. You can navigate these "drives" like any regular drive. We use the Get-PSDrive cmdlet to view them:

PS C:\> get-psdrive

Name      Used (GB)  Free (GB)  Provider      Root
----      ---------  ---------  --------      ----
Alias                           Alias
C             78.08      33.61  FileSystem    C:\
cert                            Certificate   \
D                               FileSystem    D:\
E            198.83      34.05  FileSystem    E:\
Env                             Environment
F            247.06      51.03  FileSystem    F:\
Function                        Function
HKCU                            Registry      HKEY_CURRENT_USER
HKLM                            Registry      HKEY_LOCAL_MACHINE
Variable                        Variable
WSMan                           WSMan

Obviously, your results will vary depending on what logical drives you have on your computer. You can change to any of these "drives" and use any of the file system commands you're used to like DIR and CD. The WSMan PSDrive is new to PowerShell 2.0 and gives you access to WinRM settings:

PS C:\> cd wsman:
PS WSMan:\> dir


ComputerName               Type
------------               ----
localhost                  Container
PS WSMan:\> dir localhost

 WSManConfig: Microsoft.WSMan.Management\WSMan::localhost

Name                Value
----                -----
MaxEnvelopeSizekb   150
MaxTimeoutms        60000
MaxBatchItems       32000
MaxProviderRequests 4294967295

But I wanted to point out that other PowerShell products, modules and snapins can also define new PSDrives which you may want to explore. For example, if you load the new ActiveDirectory module that is part of Windows Server 2008 R2, you will get a PSDrive defined for your Active Directory domain:

PS C:\> import-module ActiveDirectory
PS C:\> get-psdrive AD

Name      Used (GB)  Free (GB)  Provider      Root
----      ---------  ---------  --------      ----
AD                              ActiveDire... //RootDSE/
PS C:\> cd AD:
PS AD:\> dir

Name                 ObjectClass          DistinguishedName
----                 -----------          -----------------
Configuration        configuration        CN=Configuration,DC=MYCOMP...
Schema               dMD                  CN=Schema,CN=Configuration...
ForestDnsZones       domainDNS            DC=ForestDnsZones,DC=MYCOM...
RESEARCH             domainDNS            DC=RESEARCH,DC=MYCOMPANY,D...
DomainDnsZones       domainDNS            DC=DomainDnsZones,DC=RESEA...

PS AD:\> cd "dc=research,dc=mycompany,dc=local"
PS AD:\dc=research,dc=mycompany,dc=local> dir

Name                 ObjectClass          DistinguishedName
----                 -----------          -----------------
Builtin              builtinDomain        CN=Builtin,DC=RESEARCH,DC=...
Company Servers      organizationalUnit   OU=Company Servers,DC=RESE...
Computers            container            CN=Computers,DC=RESEARCH,D...
Desktops             organizationalUnit   OU=Desktops,DC=RESEARCH,DC...
Domain Controllers   organizationalUnit   OU=Domain Controllers,DC=R...
ForeignSecurityPr... container            CN=ForeignSecurityPrincipa...
Groups               organizationalUnit   OU=Groups,DC=RESEARCH,DC=M...
Infrastructure       infrastructureUpdate CN=Infrastructure,DC=RESEA...
LostAndFound         lostAndFound         CN=LostAndFound,DC=RESEARC...
Managed Service A... container            CN=Managed Service Account...
NTDS Quotas          msDS-QuotaContainer  CN=NTDS Quotas,DC=RESEARCH...
Program Data         container            CN=Program Data,DC=RESEARC...
Staff                organizationalUnit   OU=Staff,DC=RESEARCH,DC=MY...
System               container            CN=System,DC=RESEARCH,DC=M...
Users                container            CN=Users,DC=RESEARCH,DC=MY...

I changed to the AD drive and did a "directory" listing. Be careful here because it is very easy to delete "folders" and "files".

Another interesting PSDrive comes when you install SQL 2008 and include the PowerShell snapin:

PS C:\> add-pssnapin sqlserverProviderSnapin100
PS C:\> get-psdrive sqlserver

Name      Used (GB)  Free (GB)  Provider      Root
----      ---------  ---------  --------      ----
SQLSERVER                       SqlServer     SQLSERVER:\

There is also a snapin for SQL cmdlets which I'll talk about in a future lesson. The SQLSERVER PSDrive lets you easily see SQL Configuration information. I'll give you the basic commands for you to try yourself:

PS C>\> cd sqlserver:
PS SQLSERVER:\> dir sqlregistration
PS SQLSERVER:\> dir sql\$env:computername

To find child "folders" look at the PSChildName property. You can even look at individual databases:

PS SQLSERVER:\sql\godot7\SQLEXPRESS\databases> dir | select Name,*date

Name                       : ComputerData
CreateDate                 : 11/24/2009 7:39:27 AM
LastBackupDate             : 1/1/0001 12:00:00 AM
LastDifferentialBackupDate : 1/1/0001 12:00:00 AM
LastLogBackupDate          : 1/1/0001 12:00:00 AM

Name                       : VeeamBackup
CreateDate                 : 12/11/2009 11:09:32 AM
LastBackupDate             : 1/1/0001 12:00:00 AM
LastDifferentialBackupDate : 1/1/0001 12:00:00 AM
LastLogBackupDate          : 1/1/0001 12:00:00 AM

Looks like I need to run a backup!

There's a lot of information with the SQL PSDrive, much more than I can go into here. I'll be blogging about this particular topic in more detail on The Lonely Administrator blog. In the meantime, check out your PSDrives discover what treasures are hidden away.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular