Mark Minasi's Tech Forum
Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
jsclmedave

Administrator
Registered:
Posts: 482
Reply with quote  #1 
I'm Completely new to editing XML files.

I can read the lines in PowerShell but cannot figure out how to make the addition shown below.

I have to add a single entry into an existing XML file on several WIN Servers.

I am going to generalize the info but hopefully this will provide enough information.

I am going to high-lite the bits I need added -


 

<?xml version="1.0" encoding="UTF-8"?><!-- *************************************************************************************     
* MIDDLE Server Configuration     
*     
* This file contains a sample MIDDLE Server configuration.  You must edit this file to     
* change the settings as appropriate for each of your MIDDLE Server installations.     
*     
* See http://docs.NEW_APPLICATION.com/?context=MIDDLE_Server_Configuration for     
* complete documentation of the parameters that may be included in this file.     
************************************************************************************* --><parameters>
<!-- *************************************************************************************       
* REQUIRED Parameters       
*       
* This section contains parameters that MUST be included in EVERY MIDDLE Server       
* configuration.       
************************************************************************************* -->       
<!-- Tells the MIDDLE server where to contact its associated New-Application instance.  Edit             
this value to provide the URL of your organization's New-Application instance. -->       
<parameter name="url" value="https://BigDog.Application.com/"/>     

<!-- If your New-Application instance has authentication enabled (the normal case), set             
these parameters to define the user name and password the MIDDLE server will use             
to log into the instance.  -->             

<parameter name="MIDDLE.instance.username" value="Name01"/>       
<parameter encrypt="true" name="MIDDLE.instance.password" value="encrypted:n6555BR549-OU812/p8tQ=="/>         

<!-- Defines the name by which your MIDDLE server is known on the New-Application instance.             
Edit this value to provide the name you want, or leave it blank and the MIDDLE server           
will make up a name. -->       

<parameter name="name" value="BigDogServerA"/> 

<!-- *************************************************************************************
<!-- Set these parameters ONLY if your proxy requires a user name and password. -->       
<!--       
<parameter name="MIDDLE.proxy.username" value="YOUR_PROXY_USER_NAME"/>       
<parameter name="MIDDLE.proxy.password" value="YOUR_PROXY_PASSWORD" encrypt="true"/>       
-->         

<!-- These parameters specify a proxy server the MIDDLE server will use ONLY for             
downloading upgrades. -->       

<!--       
<parameter name="glide.MIDDLE.autoupgrade.proxy_host"     value="YOUR_UPGRADE_PROXY_HOST"     />       
<parameter name="glide.MIDDLE.autoupgrade.proxy_port"     value="YOUR_UPGRADE_PROXY_PORT"     />       
<parameter name="glide.MIDDLE.autoupgrade.proxy_user"     value="YOUR_UPGRADE_PROXY_USER"     />       
<parameter name="glide.MIDDLE.autoupgrade.proxy_password" value="YOUR_UPGRADE_PROXY_PASSWORD" />       
--> 

<!-- *************************************************************************************       
* LESS COMMON OPTIONAL Parameters       
*       
* There are other parameters available for more specialized needs.  These optional       
* parameters are documented on the New-Application wiki at the URL below:       
*       
*   http://docs.NEW_APPLICATION.com/?context=MIDDLE_Server_Configuration       
************************************************************************************* -->         

<!-- *************************************************************************************       
* REQUIRED Parameters that are AUTOMATICALLY filled in.       
*       
* This section contains parameters that are required, but will be automatically filled in       
* after the MIDDLE server first made contacts to your New-Application instance.       
************************************************************************************* -->         
<!-- Records the unique ID of the MIDDLE server's record on the New-Application instance.  On             
installation of the MIDDLE server, this value should be empty.  The MIDDLE server           
will fill in this value after it first contacts your New-Application instance. -->       
<parameter name="MIDDLE_sys_id" value="BR5497asdadb3f8b0051215a588-01242"/>
   
<parameter name="MIDDLE.proxy.use_proxy" value="true"/><parameter name="MIDDLE.proxy.host" value="10.99.99.90"/>
<parameter name="MIDDLE.proxy.port" value="8080"/>
<parameter name="MIDDLE.proxy.username" value="AcctName"/>
<parameter name="MIDDLE.proxy.password" value="Password"/> 
<parameter name="keypairs.MIDDLE_id" value="122334455662b1"/> 
<parameter name="MIDDLE.ssh_connections_per_host" value="100"/> 
<parameter name="MIDDLE.ssh.channel_timeout" value="300000"/> 
<parameter name="MIDDLE.ssh.set_path" value="false"/> 
<parameter name="MIDDLE.ssh.path_override" value="prepend:/home/Somename/Somebin:/home/Somename/bin:/usr/sbin:/usr/bin:/bin:/sbin"/></parameters>


encrypt="true"
  needs to be inserted after value"Password" inside of this line <parameter name="MIDDLE.proxy.password" value="Password"/>

Change This - 
<parameter name="MIDDLE.proxy.password" value="Password"/>

To This - 
<parameter name="MIDDLE.proxy.password" value="Password" encrypt="true"/>






__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 376
Reply with quote  #2 
Tim,

there are errors in the XML, comments in line 33 to 35 are fishy.
But if you remove those, you can do something like


$xml = [xml](Get-Content "c:\temp\middle.xml")
$proxypwd = $xml.SelectSingleNode("parameters/parameter[@name='MIDDLE.proxy.password']")
$proxypwd.SetAttribute("encrypted","true")
$xml.Save("c:\temp\middle2.xml")

__________________
Evgenij Smirnov

My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
jsclmedave

Administrator
Registered:
Posts: 482
Reply with quote  #3 
I manually changed some of it on purpose.  I can send you an actual copy if that will help.

This is the only part I need to update in the entire thing.

encrypt="true"  needs to be inserted after value"Password" inside of this line <parameter name="MIDDLE.proxy.password" value="Password"/>

Change This - 
<parameter name="MIDDLE.proxy.password" value="Password"/>

To This - 
<parameter name="MIDDLE.proxy.password" value="Password" encrypt="true"/>

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 376
Reply with quote  #4 
If your original file survives the conversion in the first line without throwing errors, the rest should work.
__________________
Evgenij Smirnov

My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
jsclmedave

Administrator
Registered:
Posts: 482
Reply with quote  #5 
If i do it manually it works fine.  I have 80 Servers to update and was hoping there was a way to use PowerShell or what ever to update them on the remote Servers.

I already have the steps to stop the Services as applicable and then restart them after the change at which time the PW is now encrypted the xml file.

Its just grammatically making that change remotely on each Server to all of the xml files that I'm stuck.   They are not the same file on each Server as they have local information for each Server added.

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 376
Reply with quote  #6 
Well, you can always put the above code snippet into Invoke-Command, like this:

$list_of_servers = @(<wherever you get them from>)
Invoke-Command -ComputerName $list_of_servers -ScriptBlock {Stop-Service MIDDLE; $xml = [xml](Get-Content "c:\my_config\middle.xml"); $proxypwd = $xml.SelectSingleNode("parameters/parameter[@name='MIDDLE.proxy.password']"); $proxypwd.SetAttribute("encrypted","true"); $xml.Save("c:\my_config\middle.xml"); Start-Service MIDDLE }


EDIT: That's assuming that the *path* to the file is the same on all servers.

__________________
Evgenij Smirnov

My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
jsclmedave

Administrator
Registered:
Posts: 482
Reply with quote  #7 
I will test that today!!  Thanks!!  Path will have to be a Test-Path since they were built by multiple people.

Cleaning THAT all up is next on my list.

Thanks CJ! 

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.