Welcome › Forums › General PowerShell Q&A › indexOf replace in file
This topic contains 1 reply, has 2 voices, and was last updated by
I have a list of SQL Servers in a .csv file. Some of the SQL Servers are named instances and look like this. I need to strip the slash and everything after it. This snippet does that but I am not sure how to put it in a script:
$pos = "MySQLServer001\NamedInstance".IndexOf("\")
The result is MySQLServer001
Not sure where to go from here:
$startingFile = "c:\temp\myServers.csv"
$endingFile = "c:\temp\myServers_NoSlashes.csv"
There'd be an easier way I think:
'MySQLServer001\NamedInstance' -replace '\\.*'
You should carefully read the help for Import-Csv and Export-Csv and Foreach-Object or Select-Object (calculated properties). You should read the complete help including the examples.
You must be logged in to reply to this topic.