Classes/StartmenuManager.ps1
|
class StartmenuManager { [LibraryContext]$Context [string]$DefaultSourceUrl [string]$DefaultDestinationPath StartmenuManager([LibraryContext]$context) { $this.Context = $context $this.DefaultSourceUrl = "https://raw.githubusercontent.com/kittl-partner/intune/main/windows/startmenu/start2.bin" $this.DefaultDestinationPath = "$env:LOCALAPPDATA\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState\start2.bin" } # needs to run as user! [void]UpdateStartMenuFile([string]$Url, [string]$DestinationPath) { if (-not $Url) { $Url = $this.DefaultSourceUrl } if (-not $DestinationPath) { $DestinationPath = $this.DefaultDestinationPath } $tempFile = $null try { # Create the destination directory if it doesn't exist $destinationDir = Split-Path -Path $DestinationPath if (!(Test-Path -Path $destinationDir)) { $this.Context.LogManager.Log("Creating directory: $destinationDir") New-Item -ItemType Directory -Path $destinationDir -Force } # Download the file $this.Context.LogManager.Log("Downloading file from: $Url") $tempFile = [System.IO.Path]::GetTempFileName() Invoke-WebRequest -Uri $Url -OutFile $tempFile # Copy the downloaded file to the destination $this.Context.LogManager.Log("Copying file to: $DestinationPath") Copy-Item -Path $tempFile -Destination $DestinationPath -Force $this.Context.LogManager.Log("File successfully updated.") } catch { $this.Context.LogManager.Log("An error occurred: $_", "ERROR") } finally { # Clean up temporary file if (Test-Path $tempFile) { Remove-Item -Path $tempFile -Force } $this.Context.LogManager.Log("RESTART EXLORER TO VIEW NEW START MENU!", "WARN") } } } |