PowerShell

Retrieve host name and SMB share name (UNC Path) using PowerShell

Recently I got a request to retrieve host name and SMB share name using PowerShell. This is not new and indeed there are many ways to do it and I am sharing few I like. Consider the UNC PATH is like shown below

“\\SERVER\DEMO\SMBSHARE”

Our requirement is to retrieve “SERVER” and “SMBSHARE” – Well regex is optional to use and in many cases I avoid just to remove complexity of the code.

Output is illustrated below!

Now, Let’s see how Split-Path helps us in UNC PATH – It’s very simple!

Know more information using

Here comes, another way to get HOST name from UNC path

 

Leave a Reply

Your email address will not be published. Required fields are marked *