From 648fae71dd385ad62f4f17de6b94a545700bacb2 Mon Sep 17 00:00:00 2001 From: scarrington Date: Wed, 11 Dec 2024 13:33:57 -0600 Subject: [PATCH] Desktop Rename File Upload --- Software/Desktop-Rename.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Software/Desktop-Rename.ps1 diff --git a/Software/Desktop-Rename.ps1 b/Software/Desktop-Rename.ps1 new file mode 100644 index 0000000..cbf59f5 --- /dev/null +++ b/Software/Desktop-Rename.ps1 @@ -0,0 +1,29 @@ +# Prompt the user for device type +$deviceType = Read-Host "Is the device a Desktop (1) or Laptop (2)?" + +# Validate the device type input +while ($deviceType -notin 1, 2) { + Write-Warning "Invalid input. Please enter 1 for Desktop or 2 for Laptop." + $deviceType = Read-Host "Is the device a Desktop (1) or Laptop (2)?" +} + +# Prompt the user for the device ID +$deviceId = Read-Host "Enter the device ID number:" + +# Construct the new computer name based on device type and ID +$newComputerName = if ($deviceType -eq 1) { + "DESKTOP-$deviceId" +} else { + "LAPTOP-$deviceId" +} + +# Check if the computer with the new name already exists using WMI +$existingComputer = Get-WmiObject -Class Win32_ComputerSystem -Filter "Name='$newComputerName'" + +if ($existingComputer) { + Write-Warning "A computer with the name '$newComputerName' already exists. Please choose a different ID." +} else { + # Rename the computer + Rename-Computer -NewName $newComputerName -Force + Write-Host "Computer renamed successfully to: $newComputerName" +} \ No newline at end of file