Code: Select all
[User Information]
LastName=The Dog
DisplayName=Goofy
$LastName = $UserContent["User Information"]["LastName"]
But lets say the file is not created and I want to create it with this information,
$UserContent["User Information"]["LastName"] = "The Dog"
but, when I do that I get, can't index into null array error. Which I understand because the $UserContent is basically $null and not an array at the point of reading the file. So if the file is not existent how do I setup [User Information] and nothing else?
I have tried
$UserContent["User Information"] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
But still get the can't index into null array
So, basically if I do have a file with just [User Information] in it the code works fine.