Functions/Convert-UncPathToLocalPath.ps1
<#
.SYNOPSIS Converts a path from a local path to a unc path. Example it converts 'c:\folder' to '\\MachineName\c$\folder'. .DESCRIPTION Converts a path from a local path to a unc path. Example it converts 'c:\folder' to '\\MachineName\c$\folder'. .EXAMPLE Convert-UncPathToLocalPath -Path 'c:\temp\folder\file.txt' -MachineName 'Server08' # Result: '\\Server8\c$\temp\folder\file.txt' .EXAMPLE @('C:\temp\', 'c:\temp\folder\file.txt', 'd:\item.pdf') | Convert-UncPathToLocalPath -MachineName 'Server08' # Result: #\\Server08\c$\temp\ #\\Server08\c$\temp\folder\file.txt #\\Server08\d$\item.pdf #> function Convert-UncPathToLocalPath { Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string[]] $Path ) begin{ $Paths = @() } process { foreach($Item in $Path){ if($Item -notmatch '\\\\'){ continue } $Drive = [System.IO.Path]::GetPathRoot($Item) $Dumps = $Item.Substring($Drive.Length) $Drive = $Drive.Substring($Drive.LastIndexOf('\') + 1).Replace('$',':') $Paths += "{0}{1}" -f $Drive.ToUpper(), $Dumps } } end{ $Paths } } Export-ModuleMember -Function Convert-UncPathToLocalPath |