Learning how to map a network drive
in PowerShell is much easier than the equivalent
MapNetworkDrive in VBScript.
My 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.
Note 1: The drive letter is "S:" and the Network Share in
called 'ezine' on a computer called 'grand'.
Note 2: MapNetworkDrive is a PowerShell method
applied to the comObject.
(Failed
Experiment 1)
1) Mapped a network drive to x: (\\grand\scripts) 2) Get-PSDrive x | format-List 3) Nowhere in the property list could I see reference to (\\grand\scripts) or
anything similar
(Failed Experiment 2)
1) I discovered that you could create a new drive so I tried 2) New-PSDrive y 3) Provider FileSystem (PowerShell asked for Provider) 4) Root Y:\
(PowerShell asked for Root)
In PowerShell, the command Drive revealed the new drive, however the letter Y:\ did not appear in Explorer.
Guy Recommends: A Free Trial of the Network Performance Monitor
(NPM)
SolarWinds'
Network Performance Monitor
will help you discover what's happening on your network. This
utility will also guide you through troubleshooting; the dashboard will
indicate whether the root cause is a broken link, faulty equipment or
resource overload.
What I like best is the way NPM suggests solutions to network
problems. Its also has the ability to monitor the health of individual VMware
virtual machines. If you are interested in troubleshooting, and creating
network maps, then I recommend that you try NPM now.
As 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 Cert (Certificates) Env (Environmental Variables e.g. HomeDrive, UserName) Function HKLM HKCU Variable
To list or investigate the following three 'file systems' you need the
get verb, type:
Get-Alias Get-Function
Get-Variable
SolarWinds Firewall Browser
Here is an utility where you can review firewall settings such as
access control lists (ACL), or troubleshoot problems with network
address translation (NAT).
Other reasons to download this SolarWinds Firewall Browser include
managing requests to change your firewall settings, testing firewall
rules before you go live, and querying settings with the browser's
powerful search options.
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 is 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.
The 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.
If you like this page then please share it with your friends
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is
most useful for PowerShell scripting.
SolarWinds
have produced this
Free WMI Monitor to take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.