I was close to clicking "Submit New Issue" when I finally figured things out myself, but thought this might be a useful tip to save somebody else time.
I've been trying to filter the results from Get-OdStatus when multiple folders / sites are being sync'd by OneDrive and was puzzled why the usual PS where-object didn't work. I was trying:
This would still return all five OneDrive instances on my laptop (I was expecting just my personal OD). I worked out that Get-OdStatus returns an array of objects and where-object doesn't go far enough "inside" to filter anything by a property.
I did get it working using the foreach loop below but thought that seemed a lot of code for a simple task, so kept on trying things.
This post on Stack Overflow gave me enough of a clue that I needed to use SyncRoot property, expand that with ExpandProperty and then use where-object. The final ExpandProperty parameter returns StatusString as a String so you can use it in If statement.
I was close to clicking "Submit New Issue" when I finally figured things out myself, but thought this might be a useful tip to save somebody else time.
I've been trying to filter the results from
Get-OdStatus
when multiple folders / sites are being sync'd by OneDrive and was puzzled why the usual PSwhere-object
didn't work. I was trying:Get-ODStatus | Where-Object { $_.Displayname -eq 'OneDrive - Personal' }
This would still return all five OneDrive instances on my laptop (I was expecting just my personal OD). I worked out that
Get-OdStatus
returns an array of objects andwhere-object
doesn't go far enough "inside" to filter anything by a property.I did get it working using the foreach loop below but thought that seemed a lot of code for a simple task, so kept on trying things.
This post on Stack Overflow gave me enough of a clue that I needed to use SyncRoot property, expand that with
ExpandProperty
and then usewhere-object
. The finalExpandProperty
parameter returns StatusString as a String so you can use it in If statement.Get-ODStatus | Select-Object -ExpandProperty SyncRoot | where-object {$_.DisplayName -eq 'OneDrive - Personal'} | Select-object -ExpandProperty StatusString