The script is available for download from https://gallery.technet.microsoft.com//How-to-detach-all-user-2ac10717. You can also use Microsoft Script Browser for Windows PowerShell ISE to download the sample with one button click from within your scripting environment.
This script is to detach all user databases in a SQL Server instance.
As some people asked how to detach all user databases in a SQL Server instance, this script can be used to achieve this goal when there is no session in any user database.
You can find more All-In-One Script Framework script samples at https://aka.ms/onescriptingallery