Let's say I have a virtual R:
drive that actually goes to \\\\filesrver\\share
.
How can I get the full remote path of a file, expanding net shares?
( R:\\Scripts\\s.ps1
--> \\\\fileserver\\share\\Scripts\\s.ps1
)
try this:
get-item R:\Scripts\s.ps1 |
select @{n="path";e={ "$( get-psdrive $($_.psdrive) |
select -expa displayroot)$(split-path $_ -noqualifier)" }}
My solution, also works for local paths (it doesn't change them of course):
function Get-FullRemotePath($path) {
# Attempts to expand net shares
if (!(Test-Path $path)) { return $path }
$fileObj = Get-Item $path
$remotePath = (Get-PsDrive $fileObj.PSDrive).DisplayRoot
if ($remotePath) {
$path = $remotePath+(split-path $fileobj -noqualifier)
}
return $path
}
Not a one liner though.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.