28 lines
1.2 KiB
PowerShell
28 lines
1.2 KiB
PowerShell
# Get the registry key where startup programs are stored
|
|
$registryKey = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
|
|
|
|
# Get all registry values (not child items) from the Run key
|
|
$driveEntries = Get-ItemProperty -Path $registryKey |
|
|
Get-Member -MemberType NoteProperty |
|
|
Where-Object { $_.Name -like "OneDriveSetup" -or $_.Name -like "OneDrive" }
|
|
|
|
# Check if any OneDrive entries were found
|
|
if ($driveEntries) {
|
|
foreach ($driveEntry in $driveEntries) {
|
|
try {
|
|
# Remove the registry value
|
|
Remove-ItemProperty -Path $registryKey -Name $driveEntry.Name
|
|
# Verify removal
|
|
$checkRemoval = Get-ItemProperty -Path $registryKey -Name $driveEntry.Name -ErrorAction SilentlyContinue
|
|
if ($null -eq $checkRemoval) {
|
|
Write-Host "OneDrive startup entry removed: $($driveEntry.Name)"
|
|
} else {
|
|
Write-Warning "Failed to remove OneDrive startup entry: $($driveEntry.Name)"
|
|
}
|
|
} catch {
|
|
Write-Warning "Error removing OneDrive startup entry: $($_.Exception.Message)"
|
|
}
|
|
}
|
|
} else {
|
|
Write-Warning "No OneDrive startup entries found. Please manually verify the registry key."
|
|
} |