# 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" }