- Created `DSC-UserInterfaceConfiguration.ps1` to manage user interface settings via registry changes. - Developed `DSC-WindowsFeatures.ps1` to install OpenSSH Client and enable NFS Client features. - Implemented `DSC-WindowsServices.ps1` to ensure Terminal Services are running and set to automatic startup. - Added `PS-InstallApps.ps1` to manage app installations and remove the msstore source if it exists. - Created `PS-RemoveApps.ps1` to remove unwanted apps, provisioned packages, and handle Office applications via winget.
291 lines
12 KiB
PowerShell
291 lines
12 KiB
PowerShell
# set-executionpolicy unrestricted
|
|
|
|
# Check if running as administrator
|
|
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
|
Write-Host "This script requires administrator privileges. Attempting to restart as administrator..." -ForegroundColor Yellow
|
|
|
|
# Get the current script path
|
|
$scriptPath = $MyInvocation.MyCommand.Path
|
|
|
|
# Restart the script with administrator privileges
|
|
try {
|
|
Start-Process PowerShell -Verb RunAs -ArgumentList "-ExecutionPolicy Bypass -File `"$scriptPath`""
|
|
exit
|
|
}
|
|
catch {
|
|
Write-Error "Failed to restart as administrator. Please run this script as administrator manually."
|
|
Write-Host "Right-click on PowerShell and select 'Run as administrator', then run this script again." -ForegroundColor Red
|
|
pause
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
Write-Host "Running with administrator privileges." -ForegroundColor Green
|
|
|
|
$uid = $Env:UserName
|
|
|
|
# Get the directory where this script is located
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
|
|
# Copy-Item -Path "$scriptDir\FastStone" -Destination "C:\Users\$uid\AppData\Local\" -Recurse -Force
|
|
|
|
# === FIREFOX POLICIES AND USER.JS ===
|
|
|
|
# Define the Firefox installation directory
|
|
$firefoxPath = "C:\Program Files\Mozilla Firefox"
|
|
$distributionPath = Join-Path -Path $firefoxPath -ChildPath "distribution"
|
|
|
|
# Ensure the distribution folder exists
|
|
if (-not (Test-Path -Path $distributionPath)) {
|
|
New-Item -Path $distributionPath -ItemType Directory | Out-Null
|
|
}
|
|
|
|
# Define the source and destination paths for policies.json
|
|
$sourceFile = "$scriptDir\Firefox\policies.json"
|
|
$destinationFile = Join-Path -Path $distributionPath -ChildPath "policies.json"
|
|
|
|
# Copy/replace the policies.json file
|
|
Copy-Item -Path $sourceFile -Destination $destinationFile -Force
|
|
|
|
Write-Host "policies.json has been copied/replaced in the distribution folder."
|
|
|
|
# === ShareX Configs ===
|
|
|
|
# ShareX - Remove "Capture Entire Screen" shortcut
|
|
Write-Host "Configuring ShareX shortcuts..."
|
|
|
|
# Find ShareX settings directory in Documents folder
|
|
$shareXSettingsDir = "$env:USERPROFILE\Documents\ShareX"
|
|
$settingsFile = Join-Path -Path $shareXSettingsDir -ChildPath "HotkeysConfig.json"
|
|
|
|
if (Test-Path -Path $settingsFile) {
|
|
try {
|
|
# Load the current hotkeys configuration
|
|
$hotkeysConfig = Get-Content -Path $settingsFile -Raw | ConvertFrom-Json
|
|
|
|
# Find and modify the "Capture entire screen" hotkey to disable it
|
|
foreach ($hotkey in $hotkeysConfig) {
|
|
if ($hotkey.TaskSettings.Description -eq "Capture entire screen") {
|
|
$hotkey.HotkeyInfo.IsActive = $false
|
|
Write-Host "Disabled 'Capture entire screen' hotkey in ShareX"
|
|
}
|
|
}
|
|
|
|
# Save the modified configuration back to file
|
|
$hotkeysConfig | ConvertTo-Json -Depth 10 | Set-Content -Path $settingsFile
|
|
Write-Host "ShareX hotkeys configuration updated successfully"
|
|
} catch {
|
|
Write-Warning "Failed to update ShareX hotkey configuration: $_"
|
|
}
|
|
} else {
|
|
Write-Warning "ShareX settings file not found at: $settingsFile"
|
|
}
|
|
|
|
# ShareX - Modify PrintScreen shortcuts
|
|
Write-Host "Configuring ShareX shortcuts..."
|
|
|
|
# Find ShareX settings directory in Documents folder
|
|
$shareXSettingsDir = "$env:USERPROFILE\Documents\ShareX"
|
|
$settingsFile = Join-Path -Path $shareXSettingsDir -ChildPath "HotkeysConfig.json"
|
|
|
|
if (Test-Path -Path $settingsFile) {
|
|
try {
|
|
# Load the current hotkeys configuration
|
|
$hotkeysConfig = Get-Content -Path $settingsFile -Raw | ConvertFrom-Json
|
|
|
|
# Find the Ctrl+PrintScreen entry (usually for rectangle region)
|
|
$ctrlPrintscreenEntry = $hotkeysConfig.Hotkeys | Where-Object { $_.HotkeyInfo.Hotkey -eq "PrintScreen, Control" }
|
|
if ($ctrlPrintscreenEntry) {
|
|
$ctrlPrintscreenEntry.HotkeyInfo.Hotkey = "PrintScreen"
|
|
Write-Host "Changed 'Ctrl+PrintScreen' to just 'PrintScreen'"
|
|
}
|
|
|
|
# Find the PrintScreen only entry (usually "Capture entire screen") and disable it
|
|
$printscreenEntry = $hotkeysConfig.Hotkeys | Where-Object { $_.HotkeyInfo.Hotkey -eq "PrintScreen" -and $_ -ne $ctrlPrintscreenEntry }
|
|
if ($printscreenEntry) {
|
|
# Remove the entry from the array
|
|
$newHotkeys = $hotkeysConfig.Hotkeys | Where-Object { $_ -ne $printscreenEntry }
|
|
$hotkeysConfig.Hotkeys = $newHotkeys
|
|
Write-Host "Removed entry with just PrintScreen shortcut"
|
|
}
|
|
|
|
# Save the modified configuration back to file
|
|
$hotkeysConfig | ConvertTo-Json -Depth 10 | Set-Content -Path $settingsFile
|
|
Write-Host "ShareX hotkeys configuration updated successfully"
|
|
} catch {
|
|
Write-Warning "Failed to update ShareX hotkey configuration: $_"
|
|
}
|
|
} else {
|
|
Write-Warning "ShareX settings file not found at: $settingsFile"
|
|
}
|
|
|
|
# ShareX - Replace configuration files and remove backup folder
|
|
Write-Host "Configuring ShareX..."
|
|
|
|
# Define the source and destination paths
|
|
$shareXSourceDir = ".\ShareX"
|
|
$shareXDestDir = "$env:USERPROFILE\Documents\ShareX"
|
|
$backupDir = Join-Path -Path $shareXDestDir -ChildPath "Backup"
|
|
$shareXExePath = "C:\Program Files\ShareX\ShareX.exe"
|
|
|
|
# Close ShareX if it's running
|
|
$shareXProcess = Get-Process -Name "ShareX" -ErrorAction SilentlyContinue
|
|
if ($shareXProcess) {
|
|
Write-Host "Closing ShareX process..."
|
|
$shareXProcess | Stop-Process -Force
|
|
Start-Sleep -Seconds 1 # Give it a moment to close
|
|
}
|
|
|
|
# Check if the source directory exists
|
|
if (-not (Test-Path -Path $shareXSourceDir)) {
|
|
Write-Warning "ShareX source directory not found at: $shareXSourceDir"
|
|
} else {
|
|
# Ensure the destination directory exists
|
|
if (-not (Test-Path -Path $shareXDestDir)) {
|
|
New-Item -Path $shareXDestDir -ItemType Directory -Force | Out-Null
|
|
Write-Host "Created ShareX directory at: $shareXDestDir"
|
|
}
|
|
|
|
# Delete Backup folder first if it exists
|
|
if (Test-Path -Path $backupDir) {
|
|
try {
|
|
Remove-Item -Path $backupDir -Recurse -Force
|
|
Write-Host "Removed ShareX Backup folder"
|
|
} catch {
|
|
Write-Warning "Failed to remove ShareX Backup folder: $_"
|
|
}
|
|
}
|
|
|
|
# Copy ApplicationConfig.json
|
|
$sourceAppConfig = Join-Path -Path $shareXSourceDir -ChildPath "ApplicationConfig.json"
|
|
$destAppConfig = Join-Path -Path $shareXDestDir -ChildPath "ApplicationConfig.json"
|
|
if (Test-Path -Path $sourceAppConfig) {
|
|
Copy-Item -Path $sourceAppConfig -Destination $destAppConfig -Force
|
|
Write-Host "Copied ApplicationConfig.json to $shareXDestDir"
|
|
} else {
|
|
Write-Warning "ApplicationConfig.json not found in source directory"
|
|
}
|
|
|
|
# Copy HotkeysConfig.json
|
|
$sourceHotkeysConfig = Join-Path -Path $shareXSourceDir -ChildPath "HotkeysConfig.json"
|
|
$destHotkeysConfig = Join-Path -Path $shareXDestDir -ChildPath "HotkeysConfig.json"
|
|
if (Test-Path -Path $sourceHotkeysConfig) {
|
|
Copy-Item -Path $sourceHotkeysConfig -Destination $destHotkeysConfig -Force
|
|
Write-Host "Copied HotkeysConfig.json to $shareXDestDir"
|
|
} else {
|
|
Write-Warning "HotkeysConfig.json not found in source directory"
|
|
}
|
|
}
|
|
|
|
# Restart ShareX if it was running
|
|
if ($shareXProcess -and (Test-Path -Path $shareXExePath)) {
|
|
Write-Host "Restarting ShareX with silent flag..."
|
|
Start-Process -FilePath $shareXExePath -ArgumentList "-s"
|
|
} elseif ($shareXProcess) {
|
|
Write-Warning "Could not restart ShareX: Executable not found at $shareXExePath"
|
|
}
|
|
|
|
# === XMouseButtonControl Configs ===
|
|
|
|
# XMouseButtonControl - Replace configuration files
|
|
Write-Host "Configuring XMouseButtonControl..."
|
|
|
|
# Define the source and destination paths
|
|
$xmbcSourceDir = ".\XMouseButtonControl"
|
|
$xmbcDestDir = "$env:APPDATA\Highresolution Enterprises\XMouseButtonControl"
|
|
|
|
# Ensure the destination directory exists
|
|
if (-not (Test-Path -Path $xmbcDestDir)) {
|
|
New-Item -Path $xmbcDestDir -ItemType Directory -Force | Out-Null
|
|
Write-Host "Created XMouseButtonControl directory at: $xmbcDestDir"
|
|
}
|
|
|
|
# Copy XMBCSettings.xml
|
|
$sourceSettings = Join-Path -Path $xmbcSourceDir -ChildPath "XMBCSettings.xml"
|
|
$destSettings = Join-Path -Path $xmbcDestDir -ChildPath "XMBCSettings.xml"
|
|
if (Test-Path -Path $sourceSettings) {
|
|
Copy-Item -Path $sourceSettings -Destination $destSettings -Force
|
|
Write-Host "Copied XMBCSettings.xml to $xmbcDestDir"
|
|
} else {
|
|
Write-Warning "XMBCSettings.xml not found in source directory"
|
|
}
|
|
|
|
# Copy profile file
|
|
$sourceProfile = Join-Path -Path $xmbcSourceDir -ChildPath "psymon's XMBC Settings.xmbcp"
|
|
$destProfile = Join-Path -Path $xmbcDestDir -ChildPath "psymon's XMBC Settings.xmbcp"
|
|
if (Test-Path -Path $sourceProfile) {
|
|
Copy-Item -Path $sourceProfile -Destination $destProfile -Force
|
|
Write-Host "Copied 'psymon's XMBC Settings.xmbcp' to $xmbcDestDir"
|
|
} else {
|
|
Write-Warning "psymon's XMBC Settings.xmbcp not found in source directory"
|
|
}
|
|
|
|
# === ENVIRONMENT VARIABLES AND PATH UPDATES ===
|
|
|
|
# Update Windows hosts file with entries to block license servers
|
|
Write-Host "Updating Windows hosts file..."
|
|
|
|
# Define the hosts file path
|
|
$hostsFile = "$env:SystemRoot\System32\drivers\etc\hosts"
|
|
|
|
# Define the input file path (relative to script location)
|
|
$hostsInputFile = "$scriptDir\hosts.txt"
|
|
|
|
# Check if the input file exists
|
|
if (-not (Test-Path -Path $hostsInputFile)) {
|
|
Write-Warning "hosts.txt file not found at $hostsInputFile"
|
|
} else {
|
|
try {
|
|
# Read the current hosts file
|
|
$hostsContent = Get-Content -Path $hostsFile -ErrorAction Stop
|
|
|
|
# Read the hostnames to block from the input file
|
|
$hostnamesToBlock = Get-Content -Path $hostsInputFile |
|
|
Where-Object { $_ -and $_.Trim() -ne "" -and -not $_.Trim().StartsWith("#") } |
|
|
ForEach-Object { $_.Trim() }
|
|
|
|
# Create a backup of the original hosts file
|
|
$backupFile = "$hostsFile.backup.$(Get-Date -Format 'yyyyMMdd-HHmmss')"
|
|
Copy-Item -Path $hostsFile -Destination $backupFile -Force
|
|
Write-Host "Created backup: $backupFile"
|
|
|
|
# Track if any changes were made
|
|
$changesMade = $false
|
|
|
|
# Check each hostname and add if not already present
|
|
foreach ($hostname in $hostnamesToBlock) {
|
|
# Check if this hostname is already in the hosts file (case-insensitive)
|
|
$existingEntry = $hostsContent | Where-Object {
|
|
$_ -match "^\s*127\.0\.0\.1\s+$([regex]::Escape($hostname))\s*$" -or
|
|
$_ -match "^\s*127\.0\.0\.1\s+.*\b$([regex]::Escape($hostname))\b"
|
|
}
|
|
|
|
if (-not $existingEntry) {
|
|
# Add the entry
|
|
$hostsContent += "127.0.0.1 $hostname"
|
|
Write-Host "Added: $hostname"
|
|
$changesMade = $true
|
|
} else {
|
|
Write-Host "Already exists: $hostname" -ForegroundColor DarkGray
|
|
}
|
|
}
|
|
|
|
# Write the updated hosts file if changes were made
|
|
if ($changesMade) {
|
|
$hostsContent | Set-Content -Path $hostsFile -Encoding ASCII -Force
|
|
Write-Host "Hosts file updated successfully with $($hostnamesToBlock.Count) entries processed"
|
|
} else {
|
|
Write-Host "No changes needed - all entries already exist in hosts file"
|
|
}
|
|
|
|
# Flush DNS cache to apply changes immediately
|
|
Write-Host "Flushing DNS cache..."
|
|
& ipconfig /flushdns | Out-Null
|
|
Write-Host "DNS cache flushed"
|
|
|
|
} catch {
|
|
Write-Error "Failed to update hosts file: $_"
|
|
Write-Host "Make sure the script is running with administrator privileges" -ForegroundColor Red
|
|
}
|
|
}
|