Microsoft PowerShell DrivesIntroduction to Microsoft PowerShell's DrivesMy biggest surprise with Get-psdrive was that the registry appeared in the results. I was expecting a list of the local and network drive, but I had not anticipated HKLM or ENV amongst the catalog of drives available to PowerShell. Topics for Microsoft PowerShell's DrivesGet-psdriveAs anticipated Get-psdrive (note singular noun) displays hard drives such as C:\ and D:\. Here are the extra namespaces that I was not expecting:
Alias To list or investigate the following three 'file systems' you need the get verb, type: Get-alias However to access the registry (HKLM) or Env you need the 'set' verb Set-location HKLM: (Note the colon) One interesting command is Get-psdrive name. Where name is HKLM, Variable or Alias. Childitem (also get-Childitem, or gci)In the context of a drive, PowerShell uses get-Childitem to list the contents. You may wish to use dir, or you may prefer to leave the old DOS commands at the PowerShell door and learn the new style verb-noun pairs. Incidentally, it is worth remembering that all PowerShell nouns are singular, Microsoft are determined to enforce consistency wherever possible. A handy command is set-location. Microsoft include a mapping for many old dos commands, therefore if you prefer, use the alias cd, rather than the modern set-location. MapNetworkDriveI have to confess that at first I was unable to map a network drive. However, eventually I hit upon this indirect method: Success Experiment 1 $net = $(New-Object -ComObject WScript.Network) (Failed Experiment 1) 1) Mapped a network drive to x: (\\grand\scripts) (Failed Experiment 2) 1) I discovered that you could create a new drive so I tried In PowerShell, the command Drive revealed the new drive, however the letter Y:\ did not appear in Explorer. Success Experiment 2 1) New-psdrive -name
GuyScripts -psprovider filesystem -root d:\ scripts Summary of PowerShell's DrivesThe Get-psdrive command returned more items than I expected. In amongst the usual C:\ and D:\ drive letters was HKCU and Alias. By creating a new com object it's possible to MapNetworkDrive just as you would with VBScript.
˚
See Also• Windows PowerShell Home • Introduction • Cmdlets • Exchange 2007 • Profile.ps1 • $_.Pipeline If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit. *
|
|||||