The script is available for download from https://gallery.technet.microsoft.com//How-to-check-for-duplicate-5d9dd711. You can also use Microsoft Script Browser for Windows PowerShell ISE to download the sample with one button click from within your scripting environment.
Sometimes repeated installation of software can add duplicate entries into the PATH environment variable. Since environment variable has a there is a hard coded limit in the size of this variable, there are chances that you may it that limit over a period of time. This script checks the PATH environment variable and removes any duplicate path entries.
This script was originally developed to check and remove duplicate paths in the PATH system environment variable.
Faulty software installers may add duplicate paths to the PATH environment variable. Also, there is a known bug associated with http://support2.microsoft.com/kb/2823180 - This KB adds an extra string : “%systemroot%\System32\WindowsPowerShell\v1.0\“ to the PATH environment variable. As a result the length of the PATH variable may reach close to the 32,767 limit. In some cases applications that try to add additional paths may fail. The issue can be resolved by simply removing the duplicate entries from the PATH variable.
You can find more All-In-One Script Framework script samples at https://aka.ms/onescriptingallery