Question about PowerShell searching for .exe.config, scanning contents of file, clearing contents of the defaultProxy node/element, if present, saving file

I have an issue, at my job, (due to the nature of my my job…I am not able to give a lot of details).

Could you please help me…I need to have a Powershell 5.1 script that will:

1). Find all files that have either a .exe.config extension or a .machine.config extension in a VM-Ware VM and where the OS is Windows Server 2016.

2). Search the contents of that file (or each file that is found) to see if it contains:

                          Contents/values within this defaultproxy node/element (the contents/values may or may not be present)

3). If it is found that there are any contents/values inside that node/element… then delete/clear all of those contents/values. Once the contents/values have been deleted/cleared/removed then save the file with the original name in the original location. Then move onto the next file.

        • If it is found that there are NO contents/values inside that the node/element (if it is empty or clear) then there is nothing to do… so close the file and move onto the next file.

I have done a lot of research on how to do this… but I don’t understand either the vague, very little to non-existent documentation/help/ or other information on how to do this.

Thank you,


Welcome to the forum. :wave:t3:

Please keep in mind … this forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

What have you tried so far? We expect you to make an own attempt to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

If that’s the case you may do a big step back and start with learning the very basics of PowerShell first. This will save you from a lot of wasted time and frustrations. And it will enable you to understand the help you’ll get in forums like this.

I guess you can start looking into those commands with those switches :

 Get-ChildItem c:\ -Recurse -Include -Exclude 

Then you can parse a text file to an XML object, but this is something I am not very good at, and I won’t dig further as working with XML in powershell is not something I master.

$XmlContent = [XML](get-content myfile.xml)

In either case, you will need to read the documentation and understand PowerShell basics (and more specifics regarding XML)