2

I have multiple rows of data in a powershell script that look like:

SSAS=PerformanceAnalysisService, Provider=SQLNCLI11.1;Data Source=LAP123;Integrated Security=SSPI;Initial Catalog=PerformanceDataMart:
SSAS=EnvironmentalAnalysisService, Provider=SQLNCLI11.1;Data Source=LAP123;Integrated Security=SSPI;Initial Catalog=EnvironmentalDataMart:

I'm currently using:

ConvertFrom-String -Delimiter ";" -PropertyNames Server, Provider, Source, Security, Catalog.

Which gives me:

Server                                                  Provider            Source                   Security                              
------                                                  --------            ------                   --------                              
SSAS=EnvironmentalAnalysisService, Provider=SQLNCLI11.1 Data Source=LAP123  Integrated Security=SSPI Initial Catalog=EnvironmentalDataMart:
SSAS=PerformanceAnalysisService, Provider=SQLNCLI11.1   Data Source=DEV-EDW Integrated Security=SSPI Initial Catalog=PerformanceDataMart: 

I'd like to create a table, with the key as the column headings, or even to be able to strip the key out of the table data.

+------------------------------+-------------+-------------+-----------------+-----------------------+
|            SSAS              |  Provider   | Data Source |    Security     |    Catalog            |
+------------------------------+-------------+-------------+-----------------+-----------------------+
| EnvironmentalAnalysisService | SQLNCLI11.1 | LAP123      | Integrated SSPI | EnvironmentalDataMart |
| PerformanceAnalysisService   | SQLNCLI11.1 | LAP123      | Integrated SSPI | PerformanceDataMart   |
+------------------------------+-------------+-------------+-----------------+-----------------------+

But is there a way to identify the key/column names and the strip them out dynamically?

The end result will be used by SQL. So either returning the data as seperate columns, or comma seperated would be great.

1 Answer 1

2

ConverTo-Csv should be able to do that, simply pipe the output of ConvertFrom-String to it.

> $in = "SSAS=PerformanceAnalysisService, Provider=SQLNCLI11.1;Data Source=LAP123;Integrated Security=SSPI;Initial Catalog=PerformanceDataMart:","SSAS=EnvironmentalAnalysisService, Provider=SQLNCLI11.1;Data Source=LAP123;Integrated Security=SSPI;Initial Catalog=EnvironmentalDataMart:"
> $in | ConvertFrom-String -Delimiter ";" -PropertyNames Server, Provider, Source, Security, Catalog | ConvertTo-Csv -NoTypeInformation -Delimiter ';'
"Server";"Provider";"Source";"Security"
"SSAS=PerformanceAnalysisService, Provider=SQLNCLI11.1";"Data Source=LAP123";"Integrated Security=SSPI";"Initial Catalog=PerformanceDataMart:"
"SSAS=EnvironmentalAnalysisService, Provider=SQLNCLI11.1";"Data Source=LAP123";"Integrated Security=SSPI";"Initial Catalog=EnvironmentalDataMart:"

You can also replace ConverTo-Csv with Export-Csv if you want to store the content to a CSV file, or you can pipe the output of ConvertTo-Csv to Out-File

Hope that helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.