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

Josh Marchant 1 Reputation point
2022-04-04T14:46:21.93+00:00

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
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
7,496 questions
Windows Group Policy
Windows Group Policy
A feature of Windows that enables policy-based administration using Active Directory.
2,141 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,892 questions
0 comments No comments
{count} votes