Created
February 22, 2017 23:32
-
-
Save AdamDimech/cc1ec3d59ab6afbef8c70d9ab2154837 to your computer and use it in GitHub Desktop.
Determine an UNC path from a local path (if applicable)
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
$Drive = $(get-location).Path | |
$x = new-object system.io.driveinfo($Drive) | |
$x.drivetype | Out-Null | |
If ($x.drivetype -eq "Fixed") { | |
Write-Host "`r`n`r`nSorry," $Drive "is not a networked drive." | |
} | |
Else { | |
$currentDirectory = Get-Location | |
$currentDrive = Split-Path -qualifier $currentDirectory.Path | |
$logicalDisk = Gwmi Win32_LogicalDisk -filter "DriveType = 4 AND DeviceID = '$currentDrive'" | |
$unc = $currentDirectory.Path.Replace($currentDrive, $logicalDisk.ProviderName) | |
$output = "`r`n`r`nThe UNC Path for " + $currentDirectory + " is " + $unc | |
$output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment