question

JoshMarchant-0946 avatar image
0 Votes"
JoshMarchant-0946 asked

Windows 10 - Stuck at "Preparing" screen on first logon if logon script enabled

I've set up a group policy to run a powershell script on logon. This seems to work fine if the user has logged onto a PC before, but if its the first time they log on it causes it to get stuck on the initial setup screen that appears. To bypass it I need to do CTRL ALT DEL and sign out, then log in again.

I've set the script to run with the parameter "-executionpolicy Bypass" so it should just run it immediately. Is there anything about the script that would cause it to do this?

 function Test-RegistryValue {
     param (
         [parameter(Mandatory=$true)]
         [ValidateNotNullOrEmpty()]$Path,
    
         [parameter(Mandatory=$true)]
         [ValidateNotNullOrEmpty()]$Value
     )
     try {
         Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
         return $true
     }
    
     catch {
         return $false
     }
 }
    
 $regVal = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband").FavoritesChanges
 Write-Host $regVal
    
 if ($regVal -eq 8 -or $regVal -eq $null){
     #Delete existing keys/files
     Remove-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Force -Recurse
     Remove-Item "$env:userprofile\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" -Recurse
    
     #Outlook 365 (64-bit)
     if (Test-Path -Path 'C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE' -PathType Leaf){
         #Copy shortcuts
         Copy-Item "\\swr.local\NETLOGON\Scripts\TaskbarDefault\Outlook_365_64-bit\TaskBar" -Destination "$env:userprofile\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned" -Recurse
         #Import registry keys
         reg import "\\swr.local\NETLOGON\Scripts\TaskbarDefault\Outlook_365_64-bit\default-taskbar.reg"
     }
    
     #Outlook 365 (32-bit)
     elseif (Test-Path -Path 'C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE' -PathType Leaf){
         #Copy shortcuts
         Copy-Item "\\swr.local\NETLOGON\Scripts\TaskbarDefault\Outlook_365_32-bit\TaskBar" -Destination "$env:userprofile\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned" -Recurse
         #Import registry keys
         reg import "\\swr.local\NETLOGON\Scripts\TaskbarDefault\Outlook_365_32-bit\default-taskbar.reg"
     }
    
     #Outlook 2016 (64-bit)
     elseif (Test-Path -Path 'C:\Program Files\Microsoft Office\Office16\OUTLOOK.EXE' -PathType Leaf){
         #Copy shortcuts
         Copy-Item "\\swr.local\NETLOGON\Scripts\TaskbarDefault\Outlook_2016_64-bit\TaskBar" -Destination "$env:userprofile\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned" -Recurse
         #Import registry keys
         reg import "\\swr.local\NETLOGON\Scripts\TaskbarDefault\Outlook_2016_64-bit\default-taskbar.reg"
     }
    
     #Outlook 2016 (32-bit)
     elseif (Test-Path -Path 'C:\Program Files (x86)\Microsoft Office\Office16\OUTLOOK.EXE' -PathType Leaf){
         #Copy shortcuts
         Copy-Item "\\swr.local\NETLOGON\Scripts\TaskbarDefault\Outlook_2016_32-bit\TaskBar" -Destination "$env:userprofile\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned" -Recurse
         #Import registry keys
         reg import "\\swr.local\NETLOGON\Scripts\TaskbarDefault\Outlook_2016_32-bit\default-taskbar.reg"
     }
    
     #Restart explorer to apply changes
     taskkill /IM explorer.exe /f
     start explorer.exe
    
 }
windows-10-generalwindows-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.

0 Answers