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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,354 questions
0 comments No comments
{count} votes

3 answers

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

    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

    0 comments No comments

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

    0 comments No comments