Skip to content

Instantly share code, notes, and snippets.

@potatoqualitee
Created April 15, 2015 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potatoqualitee/6dbd850ae9a69e8816bd to your computer and use it in GitHub Desktop.
Save potatoqualitee/6dbd850ae9a69e8816bd to your computer and use it in GitHub Desktop.
Join-AdminUNC
Function Join-AdminUNC {
<#
.SYNOPSIS
Parses a path to make it an admin UNC.
.EXAMPLE
Join-AdminUNC sqlserver C:\windows\system32
Output: \\sqlserver\c$\windows\system32
.OUTPUTS
String
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$servername,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$filepath
)
if (!$filepath) { return }
if ($filepath.StartsWith("\\")) { return $filepath }
if ($filepath.length -gt 0 -and $filepath -ne [System.DBNull]::Value) {
$newpath = Join-Path "\\$servername\" $filepath.replace(':\','$\')
return $newpath
}
else { return }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment