#PSTip Using UNC paths when working with PowerShell providers
When working with different PowerShell providers (PSProviders), the use of UNC paths can lead to error messages. This tip will show the pitfalls of using UNC paths when working with PowerShell providers other than the file system. For a full list of the PSProviders available on your system use the Get-PSProvider cmdlet:
|
|
The output shows the default PowerShell 2.0 providers. If you use PowerShell 3.0 or have imported, for example, ActiveDirectory or WebAdministration module, an output of your command will be different. PowerShell providers expose the PowerShell drives (PSDrive). We can change the current location to the Alias: PowerShell drive using the following command:
|
|
Use the Get-ChildItem Cmdlet to list the contents of the root of this drive. We can export the output to CSV file without a problem:
|
|
However, when we attempt to do this by using a UNC path the command fails:
|
|
There are two solutions to work around this issue. We can create a PSDrive that maps to the UNC path:
|
|
Or explicitly state the PSProvider as shown in the following example:
|
|
For more information regarding PowerShell provider you can refer to the built-in help topic by running Get-Help about_Providers.
Share on: