Created
April 15, 2015 11:21
-
-
Save potatoqualitee/6dbd850ae9a69e8816bd to your computer and use it in GitHub Desktop.
Join-AdminUNC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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