2

How to find the local path of a shared path.

My shared path is \\somemachine\shared\scripts\testing

Its local path is D:\myshares\scripts\testing

Thanks!

Geert Smelt
  • 987
  • 1
  • 7
  • 19
Pradebban Raja
  • 443
  • 5
  • 20

2 Answers2

5

Using WMI, you can get a list of shares with their local path equivalents:

PS C:\> gwmi Win32_Share
Name     Path        Description
----     ----        -----------
ADMIN$   C:\Windows  Remote Admin
C$       C:\         Default share
IPC$                 Remote IPC

You would just need to match up the Name property to your share path, then replace it to get the local path on that server using the Path property of the results:

$name = "shared"
$share = (gwmi Win32_Share | ? { $_.Name -eq $name }
$path = $share.Path + "\scripts\testing"

Note: You can also pass the -ComputerName parameter to the gwmi cmdlet to run the command against another computer. You may also need to pass the -Credential parameter to supply valid credentials.

Goyuix
  • 23,614
  • 14
  • 84
  • 128
  • Thanks!! My scenario is a bit different. I have a shared path \somemachine\shared\scripts\testing\ and there are lot of folders and files which will be added to this path. I would like to get the local path of the UNC path say, \somemachine\shared\scripts\testing\BuildDrop\Daily\ComponentX\Scripts – Pradebban Raja Nov 04 '14 at 18:10
  • I don't understand how it is different - you will have to convert the server name and share to the local path... I guess you can append all the different folders and files to that path once you have it converted? The approach would basically be the same. What have you tried and what isn't working? – Goyuix Nov 04 '14 at 21:46
  • The `Path` is empty when I use `-ComputerName` (and the remote computer is a Windows Server) – Matthieu Mar 04 '20 at 15:50
1

Just in case you don't have access to WMI, this can also be accomplished using the net command:

PS C:\> net share

Share name   Resource                        Remark

------------------------------------------------------------------------------
C$           C:\                             Default share
IPC$                                         Remote IPC
ADMIN$       C:\Windows                      Remote Admin
The command completed successfully.
Geert Smelt
  • 987
  • 1
  • 7
  • 19