I'm trying to do find/replace on an start menu XML file:
The XML file:
<LayoutModificationTemplate Version="1" xmlns="http://schemas.microsoft.com/Start/2014/LayoutModification">
<LayoutOptions StartTileGroupCellWidth="6" />
<DefaultLayoutOverride>
<StartLayoutCollection>
<defaultlayout:StartLayout GroupCellWidth="6" xmlns:defaultlayout="http://schemas.microsoft.com/Start/2014/FullDefaultLayout">
<start:Group Name="Some Group I made Up" xmlns:start="http://schemas.microsoft.com/Start/2014/StartLayout">
<start:Tile Size="4x4" Column="0" Row="0" AppUserModelID="Microsoft.Windows.Photos_8wekyb3d8bbwe!App" />
</start:Group>
</defaultlayout:StartLayout>
</StartLayoutCollection>
</DefaultLayoutOverride>
</LayoutModificationTemplate>
The script:
$StartMenuLayout = (Get-Content 'C:\temp\StartMenu.xml')
Function Edit-StartMenuLayout {
If ($StartMenuLayout -notlike '*Microsoft.Windows.Photos_cw5n1h2txyewy*'){ #Check iif the value is already changed
Try {
$StartMenuLayout -replace 'Microsoft.Windows.Photos_8wekyb3d8bbwe!App','Microsoft.Windows.Photos_cw5n1h2txyewy!App'| Set-Content -path $StartMenuLayout
}
Catch { write-host "Editing Start Menu layout XML file failed! Reason: $($ERROR.Exception)" }
}
Else{
write-host "Start Menu layout XML file already contains reference to correct application Id. Skipping..."
}
}
Edit-StartMenuLayout
The error:
Set-Content : Cannot find drive. A drive with the name '<LayoutModificationTemplate Version="1" xmlns="http' does not exist.
At line:9 char:130
+ ... Windows.Photos_cw5n1h2txyewy!App'| Set-Content -path $StartMenuLayout
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (<LayoutModifica..."1" xmlns="http:String) [Set-Content], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetContentCommand
Set-Content : Illegal characters in path.
At line:9 char:130
+ ... Windows.Photos_cw5n1h2txyewy!App'| Set-Content -path $StartMenuLayout
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (C:\Labs\ <Layo...ellWidth="6" \>:String) [Set-Content], ArgumentException
+ FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.SetContentCommand
The error only occurs only when Set-Content is used, otherwise the replace seems to work fine.