Split-Path with Root UNC Directory
By using the System.Uri
class and querying its host
property:
$uri = new-object System.Uri("\\server\folder")
$uri.host # add "\\" in front to get exactly what you asked
Note: For a UNC path, the root directory is the servername plus the share name part.
An example using regular expressions:
'\\server\share' -replace '(?<!\\)\\\w+'