Created
March 13, 2017 15:48
-
-
Save davehull/8e5b009883b3316a66e7bd1d063fd721 to your computer and use it in GitHub Desktop.
ConvertTo-DelimiterSeparatedValues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertTo-DelimiterSeparatedValues { | |
<# | |
This function is like ConverTo-CSV but with | |
support for multi-character delimiters. The | |
function will return noteproperty names as | |
a header row. | |
#> | |
param( | |
[Parameter(Mandatory=$True,ValueFromPipeLine=$True,Position=0)] | |
[pscustomobject[]]$arrObject, | |
[Parameter(Mandatory=$False,Position=1)] | |
[String]$strDelimiter=":|" | |
) | |
# Create a header row from the names of NoteProperties | |
$header = @() | |
$header += ($arrObject | Get-Member -Type NoteProperty | Select-Object -ExpandProperty Name) | |
# return the delimited header | |
$header -join $strDelimiter | |
# return delimited rows of data | |
( | |
$arrObject | ForEach-Object { | |
$arrObject_ = $_ # Name the automatic variable, we need it in the inner loop | |
( $header | ForEach-Object { | |
$arrObject_.$_ | |
} ) -join $strDelimiter | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment