This script first gathers all the NCM nodes, and then the templates enabled within NCM. For each node it compares the SysOID with each template until it finds a match. If a match isn't found, it moves up the tree, and repeats until one is.
As it, when it runs it will display verbose output, with write-host used to flag when a match is found. Simply remove the "-verbose" switch if needed
And the final output in this example is piped to "Out-Gridview", but again, update as needed if it needs to be output to CSV, HTML, etc.