function Get-UncPath { <# .SYNOPSIS Returns the UNC path of a given filename to a remote machine. .PARAMETER filePath The full file path of the file. .PARAMETER ComputerName The computer name of the remote machine. .PARAMETER IgnoreLocalPaths Switch param to return the $filePath if the ComputerName is the local machine. #> param( [Parameter(Mandatory = $true)] [Alias("Path")] [string]$filePath, [Parameter(Mandatory = $true)] [string]$ComputerName, [Parameter(Mandatory = $false)] [switch]$IgnoreLocalPaths ) $logLead = (Get-LogLeadName); Write-Verbose "$logLead Constructing UNC path for `"$filepath`" on remote host $ComputerName"; # Return the local path if UNC pathing isn't required. if($IgnoreLocalPaths.IsPresent) { if(($ComputerName -eq "localhost") -or ($ComputerName -eq $env:COMPUTERNAME) -or ($ComputerName -eq (Get-FullyQualifiedServerName))) { return $filePath } } # Get the drive letter, and strip it out of the filepath. $driveLetter = (Split-Path -Path $filePath -Qualifier); $filePath = $filePath.Substring($driveLetter.Length); $driveLetter = $driveLetter.Replace(":",""); # Build UNC path. $baseUNC = "\\$ComputerName\$driveLetter`$"; $filePath = (Join-Path $baseUNC $filePath); Write-Verbose "$logLead Constructed UNC path `"$filePath`""; return $filePath; }