question

WorkJoe-6800 avatar image
0 Votes"
WorkJoe-6800 asked IanXue-MSFT answered

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







windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

campbellkerr avatar image
0 Votes"
campbellkerr answered

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?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WorkJoe-6800 avatar image
0 Votes"
WorkJoe-6800 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.