Prevent OneDrive from Running at Startup with PowerShell

OneDrive by Microsoft, previously known as SkyDrive, is a cloud-based storage service that offers users the convenience of storing and synchronizing files, including Microsoft Office documents and photos. Integrated seamlessly into the operating system, OneDrive functions like a regular folder, making it easy for users to interact with their stored content. Both applications and Windows programs can seamlessly access data stored on OneDrive, with the option to suggest it as the primary location for storing data.

OneDrive poses challenges for enterprises seeking to safeguard corporate proprietary information. Additionally, users often struggle to ascertain the storage location, especially in certain applications. As a result, the company restricts OneDrive usage to data up to ACP level 2 to enhance information security. To minimize the client’s vulnerability, unnecessary applications should not be launched during client startup.

Run the following PowerShell:

$RegKey = “HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run”
if (Get-ItemProperty -Name OneDrive -path $RegKey -ErrorAction SilentlyContinue)
{
Remove-ItemProperty $RegKey -Name OneDrive
}

This will remove the Run key for OneDrive:

The above script deleted the registry on the current logged in user. If you want to delete on all users on the machine, use the following script:

$users = Get-ChildItem “Registry::HKEY_USERS” | Where-Object { $_.PSChildName -match ‘S-1-5-21-\d+-\d+-\d+-\d+$’ }

foreach ($user in $users) {
$userSID = $user.PSChildName
$runKey = “Registry::HKEY_USERS\$userSID\Software\Microsoft\Windows\CurrentVersion\Run”

$oneDriveValue = Get-ItemProperty -Path $runKey -Name “OneDrive” -ErrorAction SilentlyContinue

if ($oneDriveValue -ne $null) {
Write-Host “User SID: $userSID”
Write-Host “OneDrive value found in registry:”
Write-Host $oneDriveValue
Write-Host “Deleting OneDrive value…”
Remove-ItemProperty -Path $runKey -Name “OneDrive” -Force
Write-Host “OneDrive value deleted.”
Write-Host “————————“
}
}

Leave a comment

Your email address will not be published. Required fields are marked *

fourteen + 17 =