0

I've found myriad methods to retrieve data FROM a string with substrings, but what I want to do is create a new string that contains substrings. The reason for this is that I want to pass that string to a CSV through the Export-CSV cmdlet. This is in a PowerShell Forms created app.

So the plan would be to 1). Read the contents of each text box: (e.g. $endusername.text $endusernumber.text $locationname.text)

2). Store those into a new string with substrings ($formoutput.endusername $formoutput.endusernumber $formoutput.locationname)

3). Output the string to a .CSV

Export-CSV -InputObject $formoutput "c:\output\formoutput.csv"

Basically, if I take any existing cmdlet (say, Get-Mailbox), store its output as a string, and then pass that string through the Export-CSV in the way explained above, it performs exactly the way I like - creating a .CSV with each of the substrings as a column, and the contents of that substring in the appropriately headed column. I just want to be able to do that with a string containing substrings that I define.

1
  • You can create an object that contains string. SO question is one way to handle it. If you have newer versions of powershell 3.0+ you can use [pscustomobject]. Either of these will export to CSV easily. Unless you want to add anything to Get-Mailbox you can export that data right away Get-Mailbox -Identity user | Select Name,EmailAddress | Export-Csv "c:\filepath.csv" -NoTypeInformation Commented Sep 29, 2014 at 14:55

1 Answer 1

1

I think you are confusing nomenclature a little bit. It sounds like what you want is a custom object not a string. Here is some pseudo-code to get you going in the right direction:

$formOutput = New-Object PsCustomObject -Property @{'EndUserName' = $endUserName.Text;
                                                    'EndUserNumber' = $endUserNumber.Text;
                                                    'LocationName' = $locatioName.Text}
$formOutput | Export-CSV .\FileName.csv -NoTypeHeader
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.