Standard user running PS script automatically as admin

Viewed 22

Some users are experiencing problems with their OneDrive therefore we need to change the D word in Regedit to 0.

Set-ItemProperty -Path "HKEY:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Type DWord -Name "DisableFileSyncNGSC" -value 0

For HKEY_LOCAL_MACHINE you can only change it by running the regedit as admin.

I would like to have this scripted so it runs from my admin account, my admin credentials should be stored somewhere and when the user open/run the file on my public folder the regkey has been changed.

Is this possible?

1 Answers
#This variable must contain a list of dnsHostNames of the computer to connect to
$computers

#Defines the scriptblock to execute on the remote computer
$code = {
    Set-ItemProperty -Path "HKEY:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Type DWord -Name "DisableFileSyncNGSC" -value 0
}

#Runs the defined scriptblock on the specifed computers
invoke-command -ComputerName $computers -ScriptBlock $code

PowerShell Remoting (Enable-PSRemoting) must be enabled and you must have Admin Rights on the target machines. You can also use the parameter -credential to specify an alternate identity.

Related