0

I've been reading though a lot of different posts describing how to access a network drive in Powershell, and the majority of them suggest using New-PSDrive, and then include some formatting usually looking somewhat like New-PSDrive -Name K -PSProvider FileSystem -Root "\\Server01\Public"

As someone who started learning powershell very recently, the formatting of -Root hasn't been very clear since there are never any examples of how to use this drive after this single line. I'm trying to access a shared drive, G:, named Groups, and move files to and from it. When I've been moving files before, the path and destination has been written similarly to "C:\Users\..."

Why are there two \\'s at the beginning of the root definition? Does Server01 mean G:, Groups, or something else entirely? If New-PSDrive works and K: is created, can I use K: in commands the same way I would C:?

  • double-backslash at the very beginning of a path that indicates a UNC path. – Steezy Jan 20 '21 at 17:40
  • To access the drive, you can use Set-Location \\servername\sharename, with New-PSDrive you are attempting to map a new drive. – Steezy Jan 20 '21 at 17:42
  • Lastly, you can use the following for moving files. Hope this helps. `Copy-Item \\servername1\sharename1\filename.ext \\servername2\sharename2` `Remove-Item \\servername\sharename\foldername\filename.ext` – Steezy Jan 20 '21 at 17:45

1 Answers1

0

\\Server01\Public is a shared folder called Public on a server called Server01, this notation is known as a UNC Path.

Once you have mapped the share to a PSDrive using New-PSDrive -Name K -PSProvider FileSystem -Root "\\Server01\Public" you can use K: in the same way you would on a directly attached drive such as C:

For example Get-ChildItem K: to list the contents or

Move-Item "test.txt" "K:" to move files to it

SEarle1986
  • 2,113
  • 1
  • 7
  • 25