What does the error message say? What if you run the last line in CMD and replace $path with "C:\AppAssociations.xml" - does that work?
Last Line isn't Executing
I am new to PowerShell, but I am trying to use it to export an App list from windows, edit that App list, and re-import the updated App list. The problem is PowerShell does not want to run the last command. It stops after it has run the command to find and replace the variables. Can anyone advise on a solution?
#
#Variables
$path = 'C:\AppAssociations.xml'
$mail = '<Association Identifier="mailto" ProgId="AppXydk58wgm44se4b399557yyyj1w7mbmvd" ApplicationName="Mail" />'
$outlook = '<Association Identifier="mailto" ProgId="Outlook.URL.mailto.15" ApplicationName="Outlook" />'
$con = Get-Content $path
#
# Download App Associations xml
Dism /online /Export-DefaultAppAssociations:"$path";
#
# find and replace
$con | % { $_.Replace("$mail", "$outlook") } | Set-Content $path;
#
# Import updated App Associations xml
Dism /online /Import-DefaultAppAssociations:$path;
Get-Date
3 answers
Sort by: Most helpful
-
-
WorkJoe 96 Reputation points
2021-04-16T00:07:51.087+00:00 The C:\AppAssociations.xml exports to C:\
The C:\AppAssociations.xml is edited successfully to make outlook the default
The second Dism does not execute importing the file back into windows.
No error message appears.If you run the Second Dism by itself it will import properly.
----> Dism /online /Import-DefaultAppAssociations:C:\AppAssociations.xml -
Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,476 Reputation points Microsoft Vendor
2021-04-16T04:50:01.453+00:00 Hi,
You should export the app list before Get-Content or you will read a file does not exist.
$path = 'C:\AppAssociations.xml' $mail = '<Association Identifier="mailto" ProgId="AppXydk58wgm44se4b399557yyyj1w7mbmvd" ApplicationName="Mail" />' $outlook = '<Association Identifier="mailto" ProgId="Outlook.URL.mailto.15" ApplicationName="Outlook" />' # Download App Associations xml Dism /online /Export-DefaultAppAssociations:"$path" $con = Get-Content $path # find and replace $con | % { $_.Replace("$mail", "$outlook") } | Set-Content $path # Import updated App Associations xml Dism /online /Import-DefaultAppAssociations:$path Get-Date
Best Regards,
Ian Xue============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.