My goal is to take multiple PS commands, export the results into individual columns.There are no relations between the data. Currently I run 15-20 individual PS scripts that each output one column of data into their own csv file. I then take each of those 15-20 csv documents and copy/paste their individual columns into a new, single spreadsheet--into their own columns. I am trying to make this process more efficient by running one script that generates one csv file that contains multiple columns with their respected results.
Here is what my final output should look like:
Here is what my current output looks like
Here is my current rendition of the code. I have tried many variations although this is the closest I've been to a working product.
$ExportPath="\\NetworkLocation\test.csv"
$ADSG1="AD_Security_Group_Name"
$OUpath='OU=Servers,DC=sample,DC=sample,DC=org'
$TST_Script1=Get-ADGroupMember $ADSG1 | Select-object -ExpandProperty Name | Out-String
$TST_Script2=Get-ADComputer -Filter * -SearchBase $OUpath | Select-object -ExpandProperty Name | Out-String
$Object = [pscustomobject]@{
TST_Script1 = $TST_Script1
TST_Script2 = $TST_Script2
}
$Object | Export-Csv -Path $ExportPath -NoTypeInformation
Export-Csvconverts the input object into text by using the property name as the header and that property's value as a data row. If there are multiple objects with property values, then you get a row per value. You have one object with one property that happens to contain an array of values. As a result, you get one data row.