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.

Matt
  • 45,022
  • 8
  • 78
  • 119
  • You can create an object that contains string. [SO question](http://stackoverflow.com/questions/15388367/create-custom-psobject-powershell-2-0?answertab=active#tab-top) 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` – Matt Sep 29 '14 at 14:55

1 Answers1

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
EBGreen
  • 36,735
  • 12
  • 65
  • 85