We help IT Professionals succeed at work.

powershell extract string

bibi92
bibi92 asked
on
Hello,

In a script, I execute :

$sql=(Get-ItemProperty "$fullpath\Setup").SQLDataRoot
echo $sql :
Z:\mssql\INST1\MSSQL10_50.INST1\MSSQL\data\MSSQL10_50.INST1\MSSQL
How can I extract Z:\mssql\INST1?

Thanks

Regards

bibi
Comment
Watch Question

IT Infrastructure Architect
Commented:
Try..
$String = "Z:\mssql\INST1\MSSQL10_50.INST1\MSSQL\data\MSSQL10_50.INST1\MSSQL"
($String.Split("\") |  Select -first 3) -Join("\")

Open in new window

Meir RivkinFull stack Software Engineer

Commented:
(Get-ItemProperty "$fullpath\Setup").SQLDataRoot.Split("\")[0..2] -join ("\")

Open in new window

Author

Commented:
Thanks bibi