Editing XML with Powershell
We're about to finally start deploying Microsoft Edge to our systems. When we install it on a new system, we want it to become the default browser.
What I was thinking we could do is:
- Set up group policy so that it's looking for the "App Associations" file on the local system (C;\Windows\system32\appassoc.xml for example)
- Use Powershell to edit any existing lines within that file or add new ones if the lines don't exist.
Currently, the XML file doesn't exist, but I'm hoping for the powershell to be written in such a way that it could be edited for different browsers in the future.
The basic contents after install could be:
<?xml version="1.0" encoding="UTF-8"?>
<DefaultAssociations>
<Association ApplicationName="Microsoft Edge" ProgId="MSEdgeHTM" Identifier=".html"/>
<Association ApplicationName="Microsoft Edge" ProgId="MSEdgeHTM" Identifier=".htm"/>
<Association ApplicationName="Microsoft Edge" ProgId="MSEdgeHTM" Identifier="http"/>
<Association ApplicationName="Microsoft Edge" ProgId="MSEdgeHTM" Identifier="https"/>
</DefaultAssociations>
But another thing that I'm hoping to do since we're going to start setting defaults anyway is to edit this file when we install different PDF programs. If we install Reader, I want to add a new line to associate PDFs with Reader. If we install Acrobat, I want to look for that line and edit it to open them in Acrobat instead. If we uninstall Acrobat (and reinstall Reader), I want to edit the existing line to re-associate with Reader again.
My basic searching shows that displaying XML and even editing XML in powershell is relatively easy. What I'm not sure how to do are the if/then things like "if exist identifier=https, then set ApplicationName=blah & ProgID=otherblah" "else (create new configured line)
I imagine this is the most helpful place to ask, so I appreciate anyone who can point me in the right direction.
Please sign in to leave a comment.
Comments
0 comments