Use the Export-CliXml cmdlet instead of Out-File. Then use the Import-CliXml cmdlet to recreate the object.
How to assign file content into variable as object
Trần Ngọc Nam
20
Reputation points
I'm having problems like: First, I use
$localGroupMembers = Get-LocalGroupMember -Group $groupName -ErrorAction SilentlyContinue | Where-Object {$_.PrincipalSource -eq "Local"}
to get members in group and export file with
$localGroupMembers | Out-File -FilePath $reportFile -Append
And then, I want get it again with
$localGroupMembers2 = Get-Content $file
But localGroupMembers2 is not object such as localGroupMembers. So, is there a way to convert localGroupMembers2 to the same format as localGroupMembers?