Desktop Rename File Upload
This commit is contained in:
parent
c75a19845f
commit
648fae71dd
29
Software/Desktop-Rename.ps1
Normal file
29
Software/Desktop-Rename.ps1
Normal file
@ -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"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user