Solved

powershell extract string

Posted on 2012-12-21
3
401 Views
Last Modified: 2012-12-24
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
0
Comment
Question by:bibi92
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38712568
Try..
$String = "Z:\mssql\INST1\MSSQL10_50.INST1\MSSQL\data\MSSQL10_50.INST1\MSSQL"
($String.Split("\") |  Select -first 3) -Join("\")

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38712639
(Get-ItemProperty "$fullpath\Setup").SQLDataRoot.Split("\")[0..2] -join ("\")

Open in new window

0
 

Author Closing Comment

by:bibi92
ID: 38718492
Thanks bibi
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question