From 0444d658be5cb2f94c86aeee393bec3def224445 Mon Sep 17 00:00:00 2001 From: dals Date: Thu, 12 Jun 2025 13:04:09 +0200 Subject: [PATCH] fixed hostname function --- base.ps1 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/base.ps1 b/base.ps1 index 82d17cf..8af2261 100644 --- a/base.ps1 +++ b/base.ps1 @@ -550,20 +550,24 @@ if (Is-McAfeeInstalled) { #endregion McAfee Removal -# Set hostname +# Current computer name $currentName = $env:COMPUTERNAME -$hostname = Read-Host "Enter new hostname (leave blank to keep current name [$currentName])" +# Prompt for new hostname +Write-Host "Current hostname is '$currentName'." +$hostname = Read-Host "Enter new hostname (leave blank to keep current name)" + +# Check if the input is non-empty and different if (-not [string]::IsNullOrWhiteSpace($hostname) -and $hostname -ne $currentName) { try { Rename-Computer -NewName $hostname -Force -ErrorAction Stop - Write-Host "Hostname changed to $hostname. It will take effect after reboot." + Write-Host "✅ Hostname changed to '$hostname'. It will take effect after reboot." $global:hostnameChanged = $true } catch { - Write-Warning "Failed to rename computer: $($_.Exception.Message)" + Write-Warning "❌ Failed to rename computer: $($_.Exception.Message)" } } else { - Write-Host "No valid hostname provided or hostname is already set to '$currentName'. Skipping rename." + Write-Host "â„šī¸ No hostname change requested or hostname already set to '$currentName'. Skipping rename." } # Prompt for the Active Directory domain