Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function ConvertTo-UNCPath {
<#
.SYNOPSIS
Convert a path to UNC path
.DESCRIPTION
Convert a path to UNC path
.NOTES
Author: Øyvind Kallstad
Date: 26.10.2015
Version: 1.0
.INPUTS
System.String
.OUTPUTS
System.String
.LINK
https://communary.wordpress.com/
#>
[CmdletBinding()]
param (
[Parameter(Position = 2, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[string] $Path,
[Parameter(Position = 1)]
[ValidateNotNullOrEmpty()]
[string] $ComputerName
)
$pathRoot = [System.IO.Path]::GetPathRoot($Path)
Write-Output ("\\$($ComputerName)$(($Path).Replace($pathRoot, "\$($Path[0])$\"))")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment