One Script to Rule Them All: Simplifying Server-Desktop Configurations

I’ve recently acquired a few new servers and was annoyed by the repetitive, identical clicks I had to make to ensure all the desktops looked the same. Sure, one could say, “Then just stick to the standard.” But the standard isn’t efficient for me. That’s why I wrote a small script that I run upon first logging into a fresh server, so that everything is set up exactly the way I like it.

It’s not really a trick, but perhaps this little script might inspire someone out there to try something similar.

PowerShell
# Can be executed as a user, as it only modifies the logged-in user
Function Restart-Explorer 
{
  Write-Verbose -Message ('[{0} BEGIN  ] Starting {1}' -f (Get-Date).TimeofDay, $myinvocation.mycommand)
  Write-Verbose -Message "[$((Get-Date).TimeofDay) BEGIN  ] Stopping Explorer.exe process"
  Get-Process -Name Explorer | Stop-Process -Force
  # Give the process time to start
  Start-Sleep -Seconds 2
  Try 
  {
    Write-Verbose -Message "[$((Get-Date).TimeofDay) BEGIN  ] Verifying Explorer restarted"
    $null = Get-Process -Name Explorer -ErrorAction stop
  }
  Catch 
  {
    Write-Warning -Message 'Manually restarting Explorer'
    Try 
    {
      Start-Process -FilePath explorer.exe
    }
    Catch 
    {
      # This should never be called
      Throw $_
    }
  }
  Write-Verbose -Message ('[{0} END    ] Ending {1}' -f (Get-Date).TimeofDay, $myinvocation.mycommand)
}

# Hide search
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchBoxTaskbarMode -Value 0 -Type DWord -Force
# Hide Task View button
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -Type DWord -Value 0 -Force
# Change Explorer start to Explorer
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name LaunchTo -Type DWord -Value 1 -Force
# Show file extensions
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideFileExt -Value 0 -Force
# Explorer: Expand to open folder
$null = New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name NavPaneExpandToCurrentFolder -Value 1 -PropertyType DWORD -Force

Restart-Explorer