Here is a short script that gives an example of the behavior in question:
$foo = New-Object -TypeName PSCustomObject -Property @{
Username = "BSmith"
OU = "Finance"
Department = "Finance"
Description = "Accounts"
Office = "345 2nd St"
ServerName = "WFINANCE"
ShareName = "BSmith$"
LocalPath = "E:\Users\BSmith"
}
Write-Host $foo
The output is: @{ServerName=WFINANCE; Office=345 2nd St; Username=BSmith; LocalPath=E:\Users\BSmith; OU=Finance; Description=Accounts; ShareName=BSmith$; Department=Finance}
As you can see, the order of the variables being output is different than the order given when they were specified. Why is this, and how can I make the order consistent?
I have only had the chance to test this on one computer, but the order of the output is consistent between executions of the script. It also doesn't make a difference how I order the properties when declaring them. I haven't been able to test and see if a different machine will return a different order.