Replace-AllUsersLayoutModification.xml.ps1
Description:
Script replaces the default LayoutModification.xml (for new profiles), as well as loops through existing profiles and updates the current LayoutModification.xml file with the currently packaged LayoutModification.xml. This is meant to be used as an installation script in an application package which can be deployed/updated as needed for this purpose.
Essentially, it modifies LayoutModification.xml for all users.
Language:
PowerShell
Usage Type:
Standalone
Script Source:
################################################### # Replace-AllUsersLayoutModification.xml.ps1 # Author(s): Sean Huggans $ScriptVersion = "23.2.6.1" ################################################### # Variables ###################################### $LogFile = "Replace-LayoutModification.log" $LogDir = "C:\Windows\Sanford Health\Custom\LayoutModificationUpdate" $LogPath = "$($LogDir)\$($LogFile)" ################################################### # Functions ###################################### function Log-Action ($Message, $StampDateTime, $WriteHost) { ################################ # Function Version 19.5.11.4 # Function by Sean Huggans ################################ New-Item -ItemType directory -Path $LogDir -Confirm:$false -Force | out-null if (($StampDateTime -eq $false) -or ($StampDateTime -eq "no")) { $Message | Out-File $LogPath -Append } else { "[ $(get-date -Format 'yyyy.MM.dd HH:mm:ss') ] $($Message)" | Out-File $LogPath -Append } if ($WriteHost -eq $true) { Write-Host $Message } } ################################################### # Execution Logic ###################################### Log-Action -Message "Beginning LayoutModification.xml update..." foreach ($UserDir in $(Get-ChildItem -Path "C:\Users" -Force |Where-Object {(($_.Mode -like "d-*") -and (($_.Name -notlike "Default*") -or ($_.Name -eq "Default")) -and ($_.Name -notlike "ADMINI*") -and ($_.Name -ne "ALL USERS") -and ($_.Name -ne "log") -and ($_.Name -ne "ProfileSetup") -and ($_.Name -ne "Public"))})) { Log-Action -Message "Found user directory ""$($UserDir.Name)"":" # Make shell dir if not exist if (!(Test-Path -path "$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell" -PathType Container)) { New-Item -ItemType directory -Path "$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell" -Force Log-Action -Message " - Created ""\AppData\Local\Microsoft\Windows\Shell"" directory (was not present)" } Try { if ($CurrentLayoutModificationXMLFile = Get-Item -Path "$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" -ErrorAction Stop) { if ($CurrentLayoutModificationXMLFile.LastWriteTime -lt $(Get-Date -Date "02/02/2023 00:00:00")) { # If the layoutmodification xml is older than the one in this package, replace it with the one in this package Try { Copy-Item -Path "$($PSScriptRoot)\LayoutModification.xml" -Destination "$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" -force Log-Action -Message " - File is older than packaged XML, Successfully updated LayoutModification.xml with the one from this package." } catch { Log-Action -Message " - Error replacing ""$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml""!" } } else { # Leave newer file alone Log-Action -Message " - ""$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml"" is newer than the packaged XML file, skipping!" } } else { # Plant new XML file Try { Copy-Item -Path "$($PSScriptRoot)\LayoutModification.xml" -Destination "$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" -force Log-Action -Message " - XML not found, Successfully placed LayoutModification.xml with the one from this package (scenario A)." } catch { Log-Action -Message " - Error replacing ""$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml""!" } } } catch { # Plant new XML file Try { Copy-Item -Path "$($PSScriptRoot)\LayoutModification.xml" -Destination "$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" -force Log-Action -Message " - XML not found, Successfully placed LayoutModification.xml with the one from this package (scenario B)." } catch { Log-Action -Message " - Error replacing ""$($UserDir.FullName)\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml""!" } } } Log-Action -Message "Finished LayoutModification.xml update."
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.