Functions/Convert-LocalPathToUncPath.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-LocalPathToUncPath -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-LocalPathToUncPath -MachineName 'Server08' # Result: #\\Server08\c$\temp\ #\\Server08\c$\temp\folder\file.txt #\\Server08\d$\item.pdf #> function Convert-LocalPathToUncPath { Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string[]] $Path, [Parameter(Mandatory=$true)] [string] $MachineName ) begin{ $Paths = @() } process { foreach($Item in $Path){ if($Item -match '\\\\'){ $Paths += $Item continue } $Qualifier = $Item | Split-Path -Qualifier $NewQualifier = '\\{0}\{1}' -f $MachineName, $Qualifier.Replace(':','$').ToLower() $NewPath = $Item.Replace($Qualifier, $NewQualifier) $Paths += $NewPath } } end{ $Paths } } Export-ModuleMember -Function Convert-LocalPathToUncPath |