Skip to content

Instantly share code, notes, and snippets.

@stu43005
Created September 21, 2023 03:23
Show Gist options
  • Save stu43005/6c598c5a37fdc4c89cd512588ded6fd5 to your computer and use it in GitHub Desktop.
Save stu43005/6c598c5a37fdc4c89cd512588ded6fd5 to your computer and use it in GitHub Desktop.
Unlock OneDrive if it is disabled by company or school group policies.
$regpath = "HKLM:\Software\Policies\Microsoft\Windows\OneDrive"
$regname = "DisableFileSyncNGSC"
$OneDriveExe = $Env:LocalAppData + "\Microsoft\OneDrive\OneDrive.exe"
$value = Get-ItemPropertyValue -Path $regpath -Name $regname -ErrorAction SilentlyContinue
if ($value -eq 1)
{
$command = '-noprofile -command "Set-ItemProperty -Path {0} -Name {1} -Value 0 -ErrorAction SilentlyContinue"' -f $regpath,$regname
Start-Process powershell.exe -Wait -Verb RunAs -ArgumentList $command
}
$process = @(Get-Process OneDrive -ErrorAction SilentlyContinue).count
if ($process -eq 0)
{
Start-Process -FilePath $OneDriveExe
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment