Help with a registry query


i have following script query registry , return value of key, list of servers.  problem i'm not getting value server.

$servers = get-content p:\data\serverssmall.txt  foreach ($server in $servers)  {      try {          $reg = [microsoft.win32.registrykey]::openremotebasekey('localmachine', $server.computer)          $regkey = $reg.opensubkey("system\\currentcontrolset\\control\\productoptions")          $servertype = $regkey.getvalue("producttype")          ('"{0}","{1}"' -f $server.computer, $servertype) | out-file p:\data\stdout.csv -append      } catch {          ('"{0}","{1}"' -f $server.computer, $_) | out-file p:\data\stderr.csv -append      }  }

the output is:

"","servernt"  "","servernt"

it should be:

"server1","servernt"  "server2","servernt"


-al h

in $reg variable, have $server.computer, used get-content populate $servers, get-content used read text files, should have names of servers in file line line. change $server.computer $server

if find post has answered question, please mark answer. if find post helpful in anyway, please click vote helpful.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file