Closes #6859 Based on dr-j's script (cherry picked from commit 16124f00f853df8026f4af1d5720092928b4073e)