Solved

powershell extract string

Posted on 2012-12-21
3
399 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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.
A procedure for exporting installed hotfix details of remote computers using powershell
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now