question

SHUOH-8693 avatar image
0 Votes"
SHUOH-8693 asked weisnh commented

Regarding GPO and PowerShell

hi there,

I setup the GPO to change the Client's registry like the shown below:



 # ($_OneDrive = Get-Item -path HKLM:\Software\Policies\Microsoft\OneDrive -ErrorAction SilentlyContinue) -eq $null
 if((Test-Path "HKLM:\Software\Policies\Microsoft\OneDrive" -ErrorAction SilentlyContinue) -eq $true)
 {
     Write-Host $_OneDrive
    
     New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
           
     if((Test-Path "HKCR:\CLSID\{04271989-C4D2-689D-E58A-84C94193AFF6}" -ErrorAction SilentlyContinue) -eq $true)
     {
         Set-ItemProperty -Path "HKCR:\CLSID\{04271989-C4D2-689D-E58A-84C94193AFF6}" -Name ‘(Default)’ -Value "doclib (unclassified)"
     }     
              
     # if ((Get-ItemProperty “HKLM:\Software\Policies\Microsoft\TESTING” -Name “r1” -ErrorAction SilentlyContinue) -ne $null){
     #      Set-ItemProperty “HKLM:\Software\Policies\Microsoft\TESTING” -Name “r1” -Value "2020"
     # }
    
     # if(($_CLSID = Get-Item -path 'HKCR\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}'))
     # {
     #     Write-Host $_CLSID
     # }    
 }
 else
 { 
     # Set the location to the registry
     Set-Location -Path "HKLM:\Software\Policies\Microsoft"
    
     # Create a new Key
    
     Get-Item -Path "HKLM:\Software\Policies\Microsoft" | New-Item -Name "OneDrive" -Force
    
     # Create new items with values
     New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\OneDrive" -Name "SharePointOnPremFrontDoorUrl" -Value "http://win-i1ns5qsofnv:31018" -PropertyType "String" -Force
     New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\OneDrive" -Name "SharePointOnPremPrioritization" -Value 1 -PropertyType "DWord" -Force
     New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\OneDrive" -Name "SharePointOnPremTenantName" -Value "Contoso" -PropertyType "String" -Force
        
     # Get out of the Registry
     Pop-Location
 }


this part: always cannot modify the client's registry. does anyone have any idea on it?? Thanks

  if((Test-Path "HKCR:\CLSID\{04271989-C4D2-689D-E58A-84C94193AFF6}" -ErrorAction SilentlyContinue) -eq $true)
         {
             Set-ItemProperty -Path "HKCR:\CLSID\{04271989-C4D2-689D-E58A-84C94193AFF6}" -Name ‘(Default)’ -Value "doclib (unclassified)"
         }     


windows-server-powershellwindows-group-policy
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered weisnh commented

Greeting SHUOH-8693,
First of all, in order to narrow the scope of inspection, we need to clarify whether this problem is a GPO problem or a PS problem.
Therefore, if you manually change the user registry, can this operation be successful?
If it is not successful, it may be due to lack of permissions or setting errors.
If it succeeds, it is the cause of the PS. We can check the error report to solve the problem.
Looking forward to your reply.
Best wishes,
Young Yang

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Young,

the registry can be updated on Local Server by manually. on the contrary, the registry cannot be modified. and I found the GPO just be performed once. I mean when my client's computer restart, login the Domain, the GPO don't be triggered. I use the "Start-Transcript -Path "$($env:windir)\Temp\odConfiguration.txt" -Force" to trace the process.

Thanks

0 Votes 0 ·