Share via

Last Line isn't Executing

WorkJoe 96 Reputation points
2021-04-15T23:30:53.273+00:00

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 for business | Windows Server | User experience | PowerShell
0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    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.

    Was this answer helpful?

    0 comments No comments

  2. 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

    Was this answer helpful?

    0 comments No comments

  3. CK 106 Reputation points
    2021-04-15T23:41:02.88+00:00

    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?

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.