Skip to content

Set-ExplorerConfig

Windows: Configures Windows Explorer settings

#Requires -Version 5.1

[CmdletBinding()]
Param (
    [bool]$ShowHiddenFiles,

    [bool]$HideFileExtensions,

    [bool]$ShowCheckBoxes,

    [string]$ComputerName = $env:COMPUTERNAME,

    [pscredential]$Credential
)

Process {
    try {
        $scriptBlock = {
            Param($Hidden, $Extensions, $CheckBoxes, $BoundParams)
            
            $keys = @(
                "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
            )
            
            foreach ($key in $keys) {
                if ($BoundParams.ContainsKey('ShowHiddenFiles')) {
                    $val = if ($Hidden) { 1 } else { 2 }
                    Set-ItemProperty -Path $key -Name "Hidden" -Value $val -Force -ErrorAction SilentlyContinue
                }
                if ($BoundParams.ContainsKey('HideFileExtensions')) {
                    $val = if ($Extensions) { 1 } else { 0 }
                    Set-ItemProperty -Path $key -Name "HideFileExt" -Value $val -Force -ErrorAction SilentlyContinue
                }
                if ($BoundParams.ContainsKey('ShowCheckBoxes')) {
                    $val = if ($CheckBoxes) { 1 } else { 0 }
                    Set-ItemProperty -Path $key -Name "AutoCheckSelect" -Value $val -Force -ErrorAction SilentlyContinue
                }
            }
        }

        if ($ComputerName -ne $env:COMPUTERNAME) {
            $invokeParams = @{
                'ComputerName' = $ComputerName
                'ScriptBlock'  = $scriptBlock
                'ArgumentList' = @($ShowHiddenFiles, $HideFileExtensions, $ShowCheckBoxes, $PSBoundParameters)
                'ErrorAction'  = 'Stop'
            }
            if ($null -ne $Credential) {
                $invokeParams.Add('Credential', $Credential)
            }

            Invoke-Command @invokeParams
        }
        else {
            &$scriptBlock -Hidden $ShowHiddenFiles -Extensions $HideFileExtensions -CheckBoxes $ShowCheckBoxes -BoundParams $PSBoundParameters
        }

        $result = [PSCustomObject]@{
            ComputerName = $ComputerName
            Action       = "ExplorerSettingsConfigured"
            Status       = "Success"
            Timestamp    = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

If set, shows hidden files and folders.

If set, hides extensions for known file types.

If set, enables item check boxes in Explorer.

Specifies the name of the target computer. Defaults to the local computer.

Specifies a PSCredential object for remote connection.

An interactive directory of PowerShell scripts.