1

I am having a hard time making a subdirectory nested inside a current directory in a shared network drive. I can create the folder

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32> new-item

cmdlet New-Item at command pipeline position 1
Supply values for the following parameters:
Path[0]: C:\Temp\Powershell\Date
Path[1]:
Type: directory


    Directory: C:\Temp\Powershell


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        06/18/2019  10:31 AM            Date


PS C:\Windows\system32> new-item

cmdlet New-Item at command pipeline position 1
Supply values for the following parameters:
Path[0]: U:\gebersole\Documents\New Placements\UI
Path[1]:
New-Item : Cannot find drive. A drive with the name 'U' does not exist.
At line:1 char:9
+ new-item <<<<
    + CategoryInfo          : ObjectNotFound: (U:String) [New-Item], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.NewItemCommand

PS C:\Windows\system32>
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
AJG
  • 11
  • 2
  • 1
    Are you running the session as Administrator? Sounds similar to [this issue](https://stackoverflow.com/questions/4742992/cannot-access-network-drive-in-powershell-running-as-administrator/4777229) – arco444 Jun 18 '19 at 14:37
  • 1
    Could be [UAC related](https://support.microsoft.com/en-gb/help/3035277/mapped-drives-are-not-available-from-an-elevated-prompt-when-uac-is-co) – boxdog Jun 18 '19 at 14:38
  • I am running it as administrator and no luck... – AJG Jun 18 '19 at 14:42
  • It looks like that PowerShell session is unable to see your "U:\" drive. An easy way to check is to cd to that drive. If that does not work you can type in `net use` it should list the available drives. – jrider Jun 18 '19 at 14:49
  • I solved this by using \\ for every leg of the path. The reason why it was not working when i was testing the path was because it was ending at New PS U:\> Test-Path U:\gebersole\Documents\'New Placements'\CDENTAL True PS U:\> new-item – AJG Jun 18 '19 at 18:18

2 Answers2

2

By default network drives are not available in an elevated process. You can find more information here: https://support.microsoft.com/en-gb/help/3035277/mapped-drives-are-not-available-from-an-elevated-prompt-when-uac-is-co

I would recommend Workaround Method 2. Run net use or New-PsDrive on the network drive, or run the script without elevation.

The Fish
  • 1,039
  • 5
  • 6
  • So strange but its not finding that drive Status Local Remote Network ------------------------------------------------------------------------------- Unavailable L: \\10.0.0.6\qsoft Microsoft Windows Network Unavailable Q: \\nllxqlaw\lxqlaw Microsoft Windows Network Unavailable R: \\nlfps01\legal Microsoft Windows Network Unavailable S: \\nlfps01\public Microsoft Windows Network The command completed successfully. – AJG Jun 18 '19 at 14:55
  • PS C:\Windows\system32> cd "U:\" Set-Location : Cannot find drive. A drive with the name 'U' does not exist. At line:1 char:3 + cd <<<< "U:\" + CategoryInfo : ObjectNotFound: (U:String) [Set-Location], DriveNotFoundException + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand PS C:\Windows\system32> cd U:\ Set-Location : Cannot find drive. A drive with the name 'U' does not exist. At line:1 char:3 – AJG Jun 18 '19 at 14:59
  • 1
    It's not strange; it's by design. If you configure the `EnableLinkedConnections` registry value, you can see mapped drives no matter whether you're elevated or not. – Bill_Stewart Jun 18 '19 at 15:25
0

I had similar issues with trying to use a mapped drive and now only use the UNC format for the file paths.

Instead of using U:\gebersole\Documents\New Placements\UI, it might work to use the UNC format \\host-name\share-name\file_path, which in your case would be something like \\gebersole\Documents\New_Placements.

https://www.lifewire.com/unc-universal-naming-convention-818230

E. Kelly
  • 117
  • 2
  • 10
  • so the host name is actually \\nlfps01 and the path is gebersole\Documents\New Placements\UI i found the drive on the admin comp but even when i try to cd on the admin it wont find the drive this is really annoying. – AJG Jun 18 '19 at 15:45
  • When I use net use it gives me but nlfps01\it is not the directory where the subdirectory I want to create is in.. STUMPED Status Local Remote Network OK Q: \\nllxqlaw\lxqlaw Microsoft Windows Network OK R: \\nlfps01\legal Microsoft Windows Network OK S: \\nlfps01\public Microsoft Windows Network OK T: \\server2\timeclock Microsoft Windows Network OK U: \\nlfps01\it Microsoft Windows Network – AJG Jun 18 '19 at 15:46
  • @AJG if you run PowerShell on your normal user account, are you able to access the drive? Like if you did `Test-Path \\nlfps01\your\path\here` on normal PowerShell (no admin) does it work? I had similar issues with Admin not seeing network drives and it is because running as admin does not transfer any permissions from your normal account. – E. Kelly Jun 18 '19 at 16:01
  • Not from my account but i have access to the account where the drive was created and that one does but it is mapping to a folder thats not correct. I need it to map to \\nlfps01\gebersole but its mapping to \\nlfps01\it .... – AJG Jun 18 '19 at 16:12