The Determine Users Accessing a Shared Folder Using PowerShell question has a good answer. Continuing on from that How do you disconnect the users accessing the share using a powershell script.
There is a Windows command line utility called OpenFiles but I'd prefer a PowerShell / WMI solution.
Until I find a WMI (e.g. based on something like Win32_ServerConnection) or .NET object solution that lets me deal with the list of connections as first class objects rather than parsing the text output, I've come up with this solution based around the OpenFiles utility. I'm fairly concerned that it's fragile and not that obvious to modify for different needs but it seems to be working for my narrow scenario at the moment. I've kept the regex with named captures for the other parts of the output as a reference for if you need to use different parameters for openfiles /disconnect (/A /ID /OP).
Note that repeated use of Select-String is something I don't fully understand but is to do with the fact that this is necessary to get access to the named captures. See this RegEx Named Groups with Select-String posting for details. Happy to change it if someone can tell me how!
Openfiles works good for me. Although you don't need to do all that saving of openfiles /query and then disconnect them one-by-one as the "*" wildcard can be used to disconnect all open sessions you can do something like:
Which will terminate all open connections