Hello,
I'm new to hashtables and PsObjects so some help is appreciated, I don't understand why it is doing this. And I'm no expert powersheller so avoiding powershell shortcuts (and talking extra loud and slow) will help me understand what I'm doing wrong. My output:
$UserDetails UserName : {$null, Bill.Gates@myDomain.com} UserLastName : {$null, Gates} UserExpiresOn : {$null, 06/26/2019 02:03 PM} UserFirstName : {$null, Bill} UserEmail : {$null, Bill.Gates@myDomain.com}
I'm only expecting key/value pair, no $nulls or {}
History
Its a bit wordy. So in short. I have one file folder for each user. In each folder is a file "user.xml", the XML contains the fields shown above (UserName, FirstName, etc). Using powershell I've stored all those XML files (900+) into one $UserXmlData:
$UserXmlData = @() foreach ( ... ) { ... ... $UserXmlData += [Xml] (Get-Content -Path $FullFilename) }
And now that I have all the XML data, I'm trying to build my own custom object where I can merge it with other data (group info)... I'm doing that by using:
$AllDetails = @() foreach ($User in $UserXmlData) { $UserName = $User.ChildNodes.username $UserEmail = $User.ChildNodes.email $UserFirstName = $User.ChildNodes.first_name $UserLastName = $User.ChildNodes.last_name $UserExpiresOn = $User.ChildNodes.account_expire $UserDetails = New-Object -TypeName PSObject -Property @{ UserName = $UserName UserEmail = $UserEmail UserFirstName = $UserFirstName UserLastName = $UserLastName UserExpiresOn = $UserExpiresOn } $AllDetails += $UserDetails }
If I output $UserName, the expected value is shown, so I'm not sure where the extra "column" is coming from when it is put into the PsObject. If you're going to say $null cant be displayed, I understand, by why is it displayed in the PsObject output?
$UserName Bill.Gates@myDomain.com and... $UserName | ft Bill.Gates@myDomain.com
Maybe I need to trim, or convert to a string, or have a nap. I don't know anymore, is it Friday yet?