From b9706621d2d09ac6c156c6c254cc6327fa079554 Mon Sep 17 00:00:00 2001 From: andyhoffman12 Date: Thu, 19 Sep 2019 14:30:31 -0500 Subject: [PATCH 1/4] Add files via upload See my repo here: https://github.com/andyhoffman12/Start-Menu-Layout/ --- ...e-Start-Menu-Layout-XML.ps1 - Shortcut.lnk | Bin 0 -> 2329 bytes StartMenuLayout/Get-Apps-and-IDs.ps1 | 35 ++++++++++++--- StartMenuLayout/Menu.json | 42 ++++++++++++++++++ 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 - Shortcut.lnk create mode 100644 StartMenuLayout/Menu.json diff --git a/StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 - Shortcut.lnk b/StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 - Shortcut.lnk new file mode 100644 index 0000000000000000000000000000000000000000..4fbbeaafab5af60f4581e8cf84fd9d4ccddcb0a7 GIT binary patch literal 2329 zcmdT^Ur1A76#s4YP^MutA|-M{fkJoeZn|40)ZLwmado4sW^oC}xX5U2WB0CDq7qRQ zMUYY0ix}366%`9CLJ5MNdd!yyi70xAQ1PLc$j*1S`Hx8rMCx9?^PThi&Uena=bm$9 z02Z5-DDcXpXdJL^g53^`IQxI-FWy-`oqyhRAUbK8+n za&j;gOB!5fi|mN&Jc3Z^^+7=!n&ChMF@y+>5UL;r9UX))DZfs@JPp&GFf`Iu(E~4B z;NhVg0=*t^v_!&0;%ZDpAWkGbH%T1nx`<=46Sc(gXf&l>ver&EH6+YvLbQhwhhh4W z$#XZYD5f?5#lWx)6`dvJ`(`R90@CFtdiT%U)AeJN=%;x3_~yY8Y&28P5#^PDqDx3ScLmEwlW0B@OfyA@3MR}dNkqtPvzq-e6myR}wZ4G_ABcM?5i3PjXGda6agN?zDE2^yI$S5Sz z*Jzd)L^+x!2Js1^99js8B1xP~Sc79kJAdAcDpKG$zp zuK33F7ytiRt*${;tbgABHIH2s5Vgf{=PH4nxpMB5?ake$JA2Yq#oq&y{Z}hTkMZ-Z RLjx!0#>=+O{OO#T{SB6cW Date: Thu, 19 Sep 2019 14:30:52 -0500 Subject: [PATCH 2/4] Delete Create-Start-Menu-Layout-XML.ps1 - Shortcut.lnk --- ...eate-Start-Menu-Layout-XML.ps1 - Shortcut.lnk | Bin 2329 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 - Shortcut.lnk diff --git a/StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 - Shortcut.lnk b/StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 - Shortcut.lnk deleted file mode 100644 index 4fbbeaafab5af60f4581e8cf84fd9d4ccddcb0a7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2329 zcmdT^Ur1A76#s4YP^MutA|-M{fkJoeZn|40)ZLwmado4sW^oC}xX5U2WB0CDq7qRQ zMUYY0ix}366%`9CLJ5MNdd!yyi70xAQ1PLc$j*1S`Hx8rMCx9?^PThi&Uena=bm$9 z02Z5-DDcXpXdJL^g53^`IQxI-FWy-`oqyhRAUbK8+n za&j;gOB!5fi|mN&Jc3Z^^+7=!n&ChMF@y+>5UL;r9UX))DZfs@JPp&GFf`Iu(E~4B z;NhVg0=*t^v_!&0;%ZDpAWkGbH%T1nx`<=46Sc(gXf&l>ver&EH6+YvLbQhwhhh4W z$#XZYD5f?5#lWx)6`dvJ`(`R90@CFtdiT%U)AeJN=%;x3_~yY8Y&28P5#^PDqDx3ScLmEwlW0B@OfyA@3MR}dNkqtPvzq-e6myR}wZ4G_ABcM?5i3PjXGda6agN?zDE2^yI$S5Sz z*Jzd)L^+x!2Js1^99js8B1xP~Sc79kJAdAcDpKG$zp zuK33F7ytiRt*${;tbgABHIH2s5Vgf{=PH4nxpMB5?ake$JA2Yq#oq&y{Z}hTkMZ-Z RLjx!0#>=+O{OO#T{SB6cW Date: Thu, 19 Sep 2019 14:32:13 -0500 Subject: [PATCH 3/4] Add files via upload --- .../Create-Start-Menu-Layout-XML.ps1 | 200 +++++++++--------- 1 file changed, 97 insertions(+), 103 deletions(-) diff --git a/StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 b/StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 index 11671d6..137f598 100644 --- a/StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 +++ b/StartMenuLayout/Create-Start-Menu-Layout-XML.ps1 @@ -1,20 +1,43 @@ -# Set file and folder names -$LayoutPath = "C:\StartMenu" -$LayoutXMLFile = "Layout.xml" -$StartAppsFile = "StartApps.csv" -$PublisherIDsFile = "PublisherIDs.txt" +#this is the Logon script. +Param( + # Working Folder for files. Should be the same location you define Group Policy to look for the "layout.xml", This will try and grab the value from the registry' + [Parameter(Mandatory = $false)] + $layoutPath = (Split-Path -path (Get-ItemPropertyValue -Path "HKCU:\Software\Policies\Microsoft\Windows\Explorer\" -Name StartLayoutFile)) + "\" +) +#set global Error actions +$ErrorActionPreference = "Stop" +$ErrorView = "CategoryView" -# Set the output location of the layout xml file -$XmlPath = "$LayoutPath\$LayoutXMLFile" +# Set file and folder names +#the layout path does not need to be set here unless the layout path gpo is not used or if the xml path is stored on a network drive used by multiple users(why wold you use this script then) +#$layoutPath = "C:\ProgramData\StartMenu\" -# Get the text files containing groups of apps to be pinned -# The files must be named GROUPNAME.1 and GROUPNAME.2 -# where GROUPNAME = the desired display name of the group in the start menu -$GroupFiles = Get-ChildItem -Path $LayoutPath\* -Include *.1, *.2 +if (!(Test-Path -path $layoutPath)) { + Write-Error "No usable layout path found" + Write-Error $error[0].exception +} +$layoutXMLFile = $layoutPath + "Layout.xml" +$tempLayoutXMLFile = $layoutPath + "Layout_temp.xml" -# Get the Name (file name + extension) and BaseName (file name only) properties of the group files -$Group1 = $GroupFiles | Where-Object {$_.Name -match ".1"} | Select-Object -Property Name,BaseName -$Group2 = $GroupFiles | Where-Object {$_.Name -match ".2"} | Select-Object -Property Name,BaseName +$availableStartAppsJson = $layoutPath + "AvailableStartApps.json" +$menuListJson = $layoutPath + "Menu.json" + +# Load the valid start Apps list +try { + $availablestartApps = Get-Content -path $availableStartAppsJson | ConvertFrom-Json +} +catch { + Write-Warning "Unable to load StartApps from $availableStartAppsJson" + Write-Error $_ +} +# Load the menu groups +try { + $menuGroups = Get-Content $menuListJson | ConvertFrom-Json +} +catch { + Write-Warning "!!!Unable to load Menu Groups from: $menuListJson" + Write-Error $_ +} function WriteShellXML { @@ -22,6 +45,10 @@ function WriteShellXML { $writer.WriteStartElement("LayoutModificationTemplate", "http://schemas.microsoft.com/Start/2014/LayoutModification") $writer.WriteAttributeString("Version", "1") + $writer.WriteStartElement("LayoutOptions") + $writer.WriteAttributeString("StartTileGroupCellWidth", "6") + $writer.WriteEndElement() + $writer.WriteStartElement("DefaultLayoutOverride") $writer.WriteAttributeString("LayoutCustomizationRestrictionType", "OnlySpecifiedGroups") @@ -31,109 +58,76 @@ function WriteShellXML { $writer.WriteAttributeString("GroupCellWidth", "6") } -function WriteTileXML ($Group) { +function WriteTileXML ($group) { + # Write the Start Group XML Element + $writer.WriteStartElement("start", "Group", "http://schemas.microsoft.com/Start/2014/StartLayout") + $writer.WriteAttributeString("Name", $group.name) - switch ($Group) { + #this looses the order of the apps from menu.json/$group.members + $confirmedStartApps = $availablestartApps | Where-Object { $_.Name -in $group.members } - 1 {$GroupNumber = $Group1} - 2 {$GroupNumber = $Group2} + $sortedConfirmedStartApps = @() + foreach ($member in $group.members) { + $sortedConfirmedStartApps += $confirmedStartApps | Where-Object { $_.name -eq $member } } - # Get the list of apps for the designated group - $GroupApps = Get-Content -Path $LayoutPath\$($GroupNumber.Name) - - # Set the group name to be displayed in the Start Menu - $StartGroupName = $GroupNumber.BaseName - - # Write the Start Group XML Element - $writer.WriteStartElement("start", "Group", "http://schemas.microsoft.com/Start/2014/StartLayout") - $writer.WriteAttributeString("Name", $StartGroupName) - - # Set loop counter - $Counter = 0 - # Loop through the group apps list and write corresponding XML elements - foreach ($Item in $GroupApps) { - - # Get the start app info for the pinned list item - $StartApp = $StartAppsCSV | Where-Object {$_.Name -eq $Item} - - # Check for existence of start app - if ($StartApp) { - - # Determine modern or desktop app, set corresponding tile and appID types - if (($PubIDs | ForEach-Object {$StartApp.AppID -match $_} ) -contains $true) { - - $TileType = "Tile" - $AppIDType = "AppUserModelID" - } - else { - - $TileType = "DesktopApplicationTile" - $AppIDType = "DesktopApplicationID" - } - - # Determine column and row value of the tile - switch ($Counter) { - - 0 {$column = 0; $row = 0} - 1 {$column = 2; $row = 0} - 2 {$column = 4; $row = 0} - 3 {$column = 0; $row = 2} - 4 {$column = 2; $row = 2} - 5 {$column = 4; $row = 2} - 6 {$column = 0; $row = 4} - 7 {$column = 2; $row = 4} - 8 {$column = 4; $row = 4} - } - - # Write XML elements and attributes for the tile - $writer.WriteStartElement("start", $TileType, "http://schemas.microsoft.com/Start/2014/StartLayout") - $writer.WriteAttributeString("Size", "2x2") - $writer.WriteAttributeString("Column", $column) - $writer.WriteAttributeString("Row", $row) - $writer.WriteAttributeString($AppIDType, $StartApp.AppID) - $writer.WriteEndElement() - - # Increment loop counter - $Counter++ - } - } + foreach ($confirmedApp in $sortedConfirmedStartApps) { + #$confirmedApp | select AppID, Name, TileType + $index = $sortedConfirmedStartApps.IndexOf($confirmedApp) + + $row = [math]::Truncate($index / 3) * 2 + $column = ($index % 3) * 2 + Write-Output "row: $row column: $column $($confirmedApp.Name)" + + #Write XML elements and attributes for the tile + $writer.WriteStartElement("start", $confirmedApp.TileType, "http://schemas.microsoft.com/Start/2014/StartLayout") + $writer.WriteAttributeString("Size", "2x2") + $writer.WriteAttributeString("Column", $column) + $writer.WriteAttributeString("Row", $row) + $writer.WriteAttributeString($confirmedApp.AppIDType, $confirmedApp.AppID) + $writer.WriteEndElement() + } + $writer.WriteEndElement() } -# If Group 1 exists, proceed. Else, do nothing -if ($Group1) { - - # Get Start Apps list - $StartAppsCSV = Import-Csv -Path $LayoutPath\$StartAppsFile - - # Get Modern App publisher IDs - $PubIDs = Get-Content -Path $LayoutPath\$PublisherIDsFile - # Create a new XML writer settings object and configure settings - $settings = New-Object system.Xml.XmlWriterSettings - $settings.Indent = $true - $settings.OmitXmlDeclaration = $true +# Create a new XML writer settings object and configure settings +$settings = New-Object system.Xml.XmlWriterSettings +$settings.Indent = $true +$settings.OmitXmlDeclaration = $true - # Create a new XML writer - $writer = [system.xml.XmlWriter]::Create($XmlPath, $settings) +# Create a new XML writer +Try { + $writer = [system.xml.XmlWriter]::Create($tempLayoutXMLFile, $settings) # Call function to write XML shell WriteShellXML - - # Call function to write tile XML elements - WriteTileXML -Group 1 - - # Only executed if Group 2 exists - if ($Group2) { - - # Write additional end element for Group 1 - $writer.WriteEndElement() - - WriteTileXML -Group 2 + $menuGroups.menuGroup | ForEach-Object { + WriteTileXML -group $_ } - # Flush the XML writer and close the file $writer.Flush() $writer.Close() } +Catch { + Write-Warning "Atempted to write the xml but ran into an issue:" + Write-Error $_ +} +if (Test-Path -path $layoutXMLFile) { + #compares the new and old XML + $FilesDifferent = Compare-Object $(Get-Content -LiteralPath $layoutXMLFile) $(Get-Content -LiteralPath $tempLayoutXMLFile ) + Write-Output $FilesDifferent +} +else { + $FilesDifferent = $true +} + +if ($FilesDifferent) { + Write-Verbose "Start Menu Layout Updated" + Copy-Item $tempLayoutXMLFile $layoutXMLFile -verbose -Force + if (!$?) { throw $error[0].exception } +} +else { + Write-Verbose "Start Menu Layout Not Updated" +} \ No newline at end of file From b7568791e8eef73c86eae408fe8c9f73c2c49b07 Mon Sep 17 00:00:00 2001 From: andyhoffman12 Date: Fri, 7 Feb 2020 12:06:21 -0600 Subject: [PATCH 4/4] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a2afc0..9c27818 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -# PowerShell \ No newline at end of file +# PowerShell + +See this project for start menu layout changes +https://github.com/andyhoffman12/Start-Menu-Layout