In PS v2, I have a simple script obtain some info via Get-ADUser, and write that out to a CSV file.
The script works, and returns what I'm after. The only issue is one of the fields(Enabled) is being reflected in my csv file as Upper Case, while it should be mixed case.
When I remove the Export-CSV, the field values are corecctly displayed as True or False. However with the Export-CSV in place, they are returned as TRUE or FALSE.
Any idea why that would be?
$Users = Get-Content 'C:\TEMP\Users.txt'
# Define cumulative array to be used later
# Query AD to see if the User exists, and if that User is Disabled or not.
# Build Output record.
# Combine all the Users Permissions into one array
# Output to CSV file
Not sure what's going on there. I can't reproduce the problem on my machine.
Google "export-csv upper case" returns many results of good reads.
Google does return many results, though unless I'm missing something, nothing relevant that I can see.
I believe the issue is is related to this field being a Boolean value. I seem to have the same issue when returing any Boolean fields from GET-ADUser.
I tried using the ToTitleCase() method to work around that, but no luck. Inserting this into my above script –
$TextInfo = (Get-Culture).TextInfo
returns this error –
Method invocation failed because [System.Boolean] doesn't contain a method named 'ToLower'.
I am also unable to reproduce this issue, using the exact same code.
However, your workaround will work if you cast the bool to a string type, like this, for instance:
For bonus points, here's a regex match evaluator solution:
In the latter case, replace the string 'TRUE' with the relevant variable ($UserInfo.Enabled).
If the upper-casing happens within Export-Csv itself, I guess you're out of luck. Odd that it seemingly can't be reproduced.
I may have experienced this issue today at work. PowerShell and the Export-Csv cmdlet were working fine, but if you open the CSV file with Excel, it displays the values as TRUE and FALSE (and will save them that way, if you save the file back to disk from Excel.)
You must be logged in to reply to this topic.