Compare commits

...

6 Commits

Author SHA1 Message Date
Rux
a5ef4b0c93
Merge 31be3b01c6 into d49b21f881 2024-11-26 07:38:46 +01:00
Chris Titus Tech
d49b21f881 Fix onedrive remove for msapps 2024-11-25 10:07:43 -06:00
Underscore
31be3b01c6 Added comments. 2024-10-10 19:09:54 -07:00
Underscore
a9a6d7cf64 Fixes for start.ps1
- Rollback changes from #2648
- Create Variable for script location.
- irm -> Invoke-RestMethod, for Powershell standard coding practices.
- iex -> Invoke-Expression, for Powershell standard coding practices.
2024-10-10 18:59:51 -07:00
Underscore
1bc32e0aff Change irm to Invoke-RestMethod
When scripting it's best to use the full function in Powershell.
2024-10-10 15:27:39 -07:00
Underscore
6a871b1feb Add -NoExit to $powershellcmd command within Start-Process argument list. 2024-10-10 15:12:39 -07:00
2 changed files with 22 additions and 19 deletions

View File

@ -2682,17 +2682,26 @@
"
$OneDrivePath = $($env:OneDrive)
Write-Host \"Removing OneDrive\"
# Check both traditional and Microsoft Store installations
$regPath = \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OneDriveSetup.exe\"
$msStorePath = \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Appx\\AppxAllUserStore\\Applications\\*OneDrive*\"
if (Test-Path $regPath) {
$OneDriveUninstallString = Get-ItemPropertyValue \"$regPath\" -Name \"UninstallString\"
$OneDriveExe, $OneDriveArgs = $OneDriveUninstallString.Split(\" \")
Start-Process -FilePath $OneDriveExe -ArgumentList \"$OneDriveArgs /silent\" -NoNewWindow -Wait
} elseif (Test-Path $msStorePath) {
Write-Host \"OneDrive appears to be installed via Microsoft Store\" -ForegroundColor Yellow
# Attempt to uninstall via winget
Start-Process -FilePath winget -ArgumentList \"uninstall -e --purge --accept-source-agreements Microsoft.OneDrive\" -NoNewWindow -Wait
} else {
Write-Host \"Onedrive dosn't seem to be installed anymore\" -ForegroundColor Red
return
Write-Host \"OneDrive doesn't seem to be installed\" -ForegroundColor Red
Write-Host \"Running cleanup if OneDrive path exists\" -ForegroundColor Red
}
# Check if OneDrive got Uninstalled
if (-not (Test-Path $regPath)) {
# Check if OneDrive got Uninstalled (both paths)
if (Test-Path $OneDrivePath) {
Write-Host \"Copy downloaded Files from the OneDrive Folder to Root UserProfile\"
Start-Process -FilePath powershell -ArgumentList \"robocopy '$($OneDrivePath)' '$($env:USERPROFILE.TrimEnd())\\' /mov /e /xj\" -NoNewWindow -Wait
@ -2758,7 +2767,7 @@
Write-Host \"If there are Files missing afterwards, please Login to Onedrive.com and Download them manually\" -ForegroundColor Yellow
Start-Sleep 5
} else {
Write-Host \"Something went Wrong during the Unistallation of OneDrive\" -ForegroundColor Red
Write-Host \"Nothing to Cleanup with OneDrive\" -ForegroundColor Red
}
"
],

View File

@ -39,32 +39,26 @@ $sync.version = "#{replaceme}"
$sync.configs = @{}
$sync.ProcessRunning = $false
# Store latest script URL in variable.
$latestScript = "https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1"
# Check if script is running as Administrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."
$argList = @()
$PSBoundParameters.GetEnumerator() | ForEach-Object {
$argList += if ($_.Value -is [switch] -and $_.Value) {
"-$($_.Key)"
} elseif ($_.Value) {
"-$($_.Key) `"$($_.Value)`""
}
}
$script = if ($MyInvocation.MyCommand.Path) {
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
} else {
"iex '& { $(irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1) } $argList'"
}
# Partial rollback from #2648, changed irm and iex to Invoke-RestMethod and Invoke-Expression.
$script = if ($MyInvocation.MyCommand.Path) { "& '" + $MyInvocation.MyCommand.Path + "'" } else { "Invoke-RestMethod '$latestScript' | Invoke-Expression"}
$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }
# Start new process with elevated privileges
Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command $script" -Verb RunAs
break
}
# Logging
$dateTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$logdir = "$env:localappdata\winutil\logs"