<# .SYNOPSIS The intent of the script is to fix oddly broken installs of MATLAB (ON WINDOWS!!!) due to some config file corruption. .EXAMPLE Right click the script file and select run in powershell. The script will self-elevate as needed. .NOTES ----------------------------------------------------- Author: Coe Gwathney (ccg0023@uah.edu) Date: Aug 16, 2023 Version: 1.0 ----------------------------------------------------- #> begin { # Self-elevate if needed... if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine Exit } } $user_desktop = "$env:HOMEPATH\Desktop" $backup_dir_name = "matlab_backup_$(get-date -Format FileDateTime)" $matlab_appdata = "$env:APPDATA\Mathworks\MATLAB" $matlab_binary = "$env:ProgramFiles\MATLAB\R2023a\bin\matlab.exe" } process { # Kill running MATLAB processes as needed. if ( Get-Process matlab -ErrorAction SilentlyContinue ) { Get-Process matlab | Stop-Process -confirm:$false } Start-Sleep -Seconds 5 # Create a stash folder. New-Item -Path "$user_desktop" -Name $backup_dir_name -ItemType Directory # Move config and licensing to that stash folder. Get-ChildItem -Path $matlab_appdata | foreach { Move-Item -Path $_.FullName -Destination "$user_desktop\$backup_dir_name" -Force } $wshell = New-Object -ComObject Wscript.Shell $wshell.Popup("Operation Completed",0,"Done",0x1) } end {}