Hi there,
There are two user accounts, one is Administrator; another is normal user.
- AD Domain: Windows Server 2019 with GPO <Running PowerShell Logon Scripts>
- Client: Windows 10: (A) Use Administrator to login the AD Domain: GPO works well and add registry to HKLM; (B) Use normal User to login the AD Domain: GPO something went wrong and failed to add registry to HKLM.
The (B) situation: I copy the PowerShell to Windows 10 Client and perform the script, I got the error message:
New-Item : Access to the registry key
'HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\OneDrive' is denied.
At C:\Users\alanb\Desktop\Handling_OneDrive_REG.ps1:47 char:58
- ... HKLM:\Software\Policies\Microsoft" | New-Item -Name "OneDrive" -Force
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH...rosoft\OneDrive:S
tring) [New-Item], UnauthorizedAccessException
- FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShel
l.Commands.NewItemCommand
New-ItemProperty : Cannot find path 'HKLM:\Software\Policies\Microsoft\OneDrive'
because it does not exist.
At C:\Users\alanb\Desktop\Handling_OneDrive_REG.ps1:50 char:5
- New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\OneDriv ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : ObjectNotFound: (HKLM:\Software...rosoft\OneDrive:Str
ing) [New-ItemProperty], ItemNotFoundException
- FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemProp
ertyCommand
New-ItemProperty : Cannot find path 'HKLM:\Software\Policies\Microsoft\OneDrive'
because it does not exist.
At C:\Users\alanb\Desktop\Handling_OneDrive_REG.ps1:51 char:5
- New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\OneDriv ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : ObjectNotFound: (HKLM:\Software...rosoft\OneDrive:Str
ing) [New-ItemProperty], ItemNotFoundException
- FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemProp
ertyCommand
New-ItemProperty : Cannot find path 'HKLM:\Software\Policies\Microsoft\OneDrive'
because it does not exist.
At C:\Users\alanb\Desktop\Handling_OneDrive_REG.ps1:52 char:5
- New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\OneDriv ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : ObjectNotFound: (HKLM:\Software...rosoft\OneDrive:Str
ing) [New-ItemProperty], ItemNotFoundException
- FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemProp
ertyCommand
I also setup some settings as the following:
- the NTFS “Read & Execute” permissions for the Domain Computers group in the ps1 file permissions
- setup Computer Configuration -> Administrative Templates -> System -> Group Policy section. Enable the “Configure Logon Script Delay” policy and specify a delay in minutes before starting the logon scripts (sufficient to complete the initialization and load all necessary services). --> 1-2 minutes.
- The security settings for running the PowerShell script can be configured via the “Turn On Script Execution” policy (in the GPO Computer Configuration section -> Administrative Templates -> Windows Components -> Windows PowerShell) --> Allow all scripts (unrestricted)
Thanks