Hi guys,
This should be a really simple problem. In my script, I need to extract a servername from a string.
String goes like
\\SERVERNAME\Sharename\Directory\Directory\
I think Regex is the easiest way to do this, but I cannot figure out how to do it.
I have tried:
and
But this did not work, and both my Google-Fu and my brain seems defective right now.
Help!
By the way, I can also get this string as an object from an XML file, if it is easier to use Regex on an object.
This should be a really simple problem. In my script, I need to extract a servername from a string.
String goes like
\\SERVERNAME\Sharename\Directory\Directory\
I think Regex is the easiest way to do this, but I cannot figure out how to do it.
I have tried:
Code:
$FullString = '\\SERVERNAME\Sharename\Directory\Directory\'
$ServerString = $FullString -match "\\\?\\"
Code:
$FullString = '\\SERVERNAME\Sharename\Directory\Directory\'
$ServerString = $FullString -replace "\\\?\\" ""
But this did not work, and both my Google-Fu and my brain seems defective right now.
Help!
By the way, I can also get this string as an object from an XML file, if it is easier to use Regex on an object.
