How to use -Path in New-PSDrive : Powershell network drives

1.7k views Asked by At

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:?

1

There are 1 answers

0
SE1986 On

\\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