I have a question regarding COM object output saved to a variable in PowerShell:
$netShare = New-Object -ComObject HNetCfg.HNetShare
$connections = $netShare.EnumEveryConnection
$connectionsProps = $connections | ForEach-Object { $netShare.NetConnectionProps.Invoke($_) }
After accessing the variable $connections once, the variable content is cleared and you cannot reuse it later in a script. While easy to workaround, why is this happening and can you prevent it?