I am triying to compare diferences between a saved copy and a copy in RAM of the list of Teams users (MicrosoftTeams ps module)
I would like to get just the modified objects when I run compare-object
$CsOnlineUserList = Get-CsOnlineUser -ResultSize ([int32]::MaxValue) |select displayname,userprincipalname,SipAddress,Identity,StateorProvince,city,State,company,InterpretedUserType,Hostingprovider,enterprisevoiceenabled,lineuri,CallingLineIdentity,OnlineVoiceRoutingPolicy,DialPlan,TenantDialPlan,TeamsUpgradePolicy,TeamsUpgradeEffectiveMode
$CsOnlineUserList | Export-Csv -NoTypeInformation -Path ("CsOnlineUserList.csv")
#$CsOnlineUserList |Export-Csv -NoTypeInformation -Path ("TEMPCsOnlineUserList.csv")
#$CsOnlineUserList = (Import-Csv -Path ("TEMPCsOnlineUserList.csv"))
$CachedCsOnlineUserList = (Import-Csv -Path ("CsOnlineUserList.csv") |select displayname,userprincipalname,SipAddress,Identity,StateorProvince,city,State,company,InterpretedUserType,Hostingprovider,enterprisevoiceenabled,lineuri,CallingLineIdentity,OnlineVoiceRoutingPolicy,DialPlan,TenantDialPlan,TeamsUpgradePolicy,TeamsUpgradeEffectiveMode)
$ModifiedObjList2 = Compare-Object -ReferenceObject $CachedCsOnlineUserList -DifferenceObject $CsonlineuserList -Property displayname,userprincipalname,SipAddress,Identity,StateorProvince,city,State,company,InterpretedUserType,Hostingprovider,enterprisevoiceenabled,lineuri,CallingLineIdentity,OnlineVoiceRoutingPolicy,DialPlan,TenantDialPlan,TeamsUpgradePolicy,TeamsUpgradeEffectiveMode
$CsOnlineUserList.count
$CachedCsOnlineUserList.count
$ModifiedObjList2.count
For some reason the only way I can get compare-object to do what it is supposed to is to export the variable into CSV file, then import it again from CSV into the same variable (commented lines)
Is there a better way to do this?