When working with a drive mapped to a Linux share, filenames are case sensitive. PowerShell handles this as expected, but I'd like to sort the output in a manner analogous to the sort order used in the "C" locale, which means sorting by character value in ascending order from U+0000 all the way through U+10FFFF (e.g. '0foo' comes before 'Foo' and 'Foo' comes before 'bar' and 'bar' comes before 'foo')
To illustrate the problem:
PS > gci Z:\foo | sort -casesensitive
xyz
Xyz
XYZ
yZ
YZ
Output desired:
XYZ
Xyz
YZ
xyz
yZ
I tried setting the current thread's culture variables to [System.Globalization.CultureInfo]::InvariantCulture
, but I had no success:
$thrd = [Threading.Thread]::CurrentThread
$thrd.CurrentCulture = [Globalization.CultureInfo]::InvariantCulture
$thrd.CurrentUICulture = $thrd.CurrentCulture
Am I even close when I assume it has to do with the culture info, or am I really far off track? Does anybody have any idea where I should start? I'm guessing I need to temporarily create a CultureInfo instance that has the behavior I desire, but it only has getters as far as CompareInfo goes, not to mention I'm unsure of how to overload the CompareInfo.Compare function that Sort-Object requires using PowerShell functions. Or is this effectively a lost cause because that isn't possible?
Edit
At the very least, would it be possible to sort with uppercase characters first, as in XYZ, Xyz, xyz, YZ, yZ?