Private/Update-UserProfile.ps1
<#
.SYNOPSIS Initializes and cleans up a user profile by removing specific files and creating necessary shortcuts. .DESCRIPTION This script performs various cleanup and setup tasks on a user profile: - Removes specific unwanted files from the desktop. - Copies necessary shortcuts to specific locations. - Ensures certain directories exist and copies required files into them. - Creates a Windows PowerShell shortcut. .PARAMETER Parameters A hashtable containing all the required parameters. .PARAMETER LogPath The path to the log file where log messages will be written. .PARAMETER ProfileDesktopPath The path to the user's desktop directory where files are managed. .PARAMETER AppDataRoamingPath The path to the user's AppData Roaming directory where shortcuts are copied. .PARAMETER LocalStatePath The path to the user's LocalState directory where required files are copied. .PARAMETER StartMenuProgramsPath The path to the user's Start Menu Programs directory where the Windows PowerShell shortcut is created. .PARAMETER FilesToRemove An array of filenames that need to be removed from the desktop. .PARAMETER StartBinPath The path to the start2.bin file that needs to be copied to the LocalState directory. .PARAMETER DesktopShortcutPath The path to the Desktop (create shortcut).DeskLink file that needs to be copied to the desktop. .EXAMPLE $params = @{ LogPath = "C:\Logs\ProfileSetup.log" ProfileDesktopPath = "C:\Users\JohnDoe\Desktop" AppDataRoamingPath = "C:\Users\JohnDoe\AppData\Roaming\Microsoft\Windows\SendTo" LocalStatePath = "C:\Users\JohnDoe\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState" FilesToRemove = @('Internet Explorer.lnk', 'Training.url', 'test.url', 'LMS.url', 'Teams.lnk') StartBinPath = "C:\Temp\start2.bin" DesktopShortcutPath = "C:\Temp\Desktop (create shortcut).DeskLink" } Update-UserProfile -Parameters $params # Update the user profile based on the provided parameters #> function Update-UserProfile { [Diagnostics.CodeAnalysis.SuppressMessageAttribute( <#Category#>'PSUseShouldProcessForStateChangingFunctions', <#CheckId#>'', Scope='Function', Justification = 'Not needed for a private cmdlet' )] [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [hashtable]$Parameters ) try { $LogPath = $Parameters.LogPath if ($Parameters.FilesToRemove) { Remove-SpecificFile -FolderPath $Parameters.ProfileDesktopPath -LogPath $LogPath -FilesToRemove $Parameters.FilesToRemove } else { Write-Log -Message "Files to remove are null, skipping file removal." -LogPath $LogPath } if ($Parameters.AppDataRoamingPath -and $Parameters.DesktopShortcutPath) { Copy-DesktopShortcut -AppDataRoamingPath $Parameters.AppDataRoamingPath -LogPath $LogPath -DesktopShortcutPath $Parameters.DesktopShortcutPath } else { Write-Log -Message "AppDataRoamingPath or DesktopShortcutPath is null, skipping desktop shortcut copy." -LogPath $LogPath } if ($Parameters.LocalStatePath -and $Parameters.StartBinPath) { Test-LocalStateDirectory -LocalStatePath $Parameters.LocalStatePath -LogPath $LogPath -StartBinPath $Parameters.StartBinPath } else { Write-Log -Message "LocalStatePath or StartBinPath is null, skipping start2.bin copy." -LogPath $LogPath } } catch { Write-Log -Message "An error occurred: $_" -LogPath $LogPath } } |