xml - Get appSettings key value in Powershell -


I'm new to the script ... so please bare me along.

I am trying to get a value from a config file on many computers.

Here is the file on each computer .... I am trying to get the \ gm107a \ Updates \ QC in a CSV file with the computer name.

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Configuration & gt; & Lt; AppSettings & gt; & Lt; Add key = "updatelocation" value = "\\ gm107a \ update \ QC" /> & Lt; Add key = "filename" value = "QualityControl.exe" /> & Lt; / AppSettings & gt; & Lt; / Configuration & gt;  

I got it to start: Then found it and tried to put it together .... Remember that I am a new brand.

Here's what I have:

  FunctionWhat {$ hostnamenodes = get-contentC: \ script \ computers.txt foreach (hostname $ $ hostname in hostname) {{Xml] $ xml = Get-content \\ $ hostname \ c $ \ drivers \ version. Code # hostcard array $ masterArray = new object psobject -Property @ {"ServerName" = $ hostname "updatelocation" = $ xml.SelectNodes ('// add [@ key = "Updatelocation"] / @ value') [0]. ' # Text '} write output $ masterarray}} vert | Select service name, update Export-Csv QA.csv -NoTypeInformation  

Here I get the error:

  indexing in a type of object Unable to System.Xml.XPathNodeList in: \ script \ get-content.ps1: 13 characters: 88 + "updatelocation" = $ xml.SelectNodes ('// add [@ key = "updatelocation"] / @ value') [& Lt; & Lt; & Lt; & Lt; 0]. '# Text' + class info: invalid operation: (0: int 32) [], runtime exposure + fullquaired error id: canot index  

edit my script with the solution below After that I get the following error now:

Here is the new error that I am getting:

  Unable to list in a type of object System.Xml.XPathNodeList C: \ Scripts \ get-content.ps1: 9 char: 92 + "updatelocation" = $ xml.SelectNodes ('// add [@ key = "updatelocation"] / @ value') [& lt; & Lt; & Lt; & Lt; 0]. '# Text'} + class info: invalid operation: (0: int 32) [], runtime expansion + fullquake-qualified underlying: canot index  

OK tried it in a different way and it works !!!! Wow! Thanks for your help with error checking!

  "updatelocation" = $ xml.configuration.appSettings.add | Where-object {$ _. Key - eC 'update deallocation'} | Choose - Object-ExpandProfility Value  

Comments

Popular posts from this blog

graphviz - size of node with shape=circle -

android - TCP sending with Unity -

properties - C#: How to set default value for a property in a partial class? -