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:?
\\Server01\Public
is a shared folder calledPublic
on a server calledServer01
, 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 useK:
in the same way you would on a directly attached drive such asC:
For example
Get-ChildItem K:
to list the contents orMove-Item "test.txt" "K:"
to move files to it