Reputation: 1
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:?
Upvotes: 0
Views: 4259
Reputation: 1
Remember if you are using parameters or variables to define your -name to use in Get-ChildItem you need to tack a ":" to the end of the variable content or it will look for a folder value of the variable in whatever your current directory is. FunFacts. :)
Upvotes: 0
Reputation: 2760
\\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
Upvotes: 0