Currently trying to figure out how to export a string to a CSV file. I’m working on a larger script, and I’m putting together a mini test script to figure this part out. I know how to get PowerShell to add entries to a CSV using PSCustomObject, what I can’t figure out is how to get PowerShell to add a specific string entry (such as “valid” or “this is incorrect”). What I have right now looks like this:
$CSVLog = New-Item "\file pathLogs$(Get-Date -f yyyy-MM-dd_hh-mm-ss) Test Log.csv" -ItemType File -Force
$CSVLog.Add(
[PSCustomObject]@{
'Column 1' = [string]::"Test" #Yeah, didn't think it would be this simple, but had to try...
}
)
Export-CSV -NoTypeInformation -Path $CSVLog -Append
Of course, what I’m doing right now only throws out an error in the Host. What do I have to do in the "Test"
portion to make this work?