You can use a PowerShell script to rename computers based on their region, building, and floor. The script can be deployed via SCCM to rename multiple machines. Below is a PowerShell script that takes the region, building, and floor as parameters to generate a new computer name and rename the computer accordingly.
This script can be adapted to run as a task sequence or package in SCCM.
param (
[Parameter(Mandatory=$true)]
[string]$Region,
[Parameter(Mandatory=$true)]
[string]$Building,
[Parameter(Mandatory=$true)]
[string]$Floor
)
# Generate the new computer name
$newComputerName = "${Region}-${Building}-${Floor}-$(Get-Random -Minimum 1000 -Maximum 9999)"
# Get the current computer name
$currentComputerName = (Get-WmiObject -Class Win32_ComputerSystem).Name
# Rename the computer
Rename-Computer -NewName $newComputerName -Force -PassThru
# Restart the computer to apply changes
Restart-Computer -Force
Steps to Deploy via SCCM
Save the Script: Save the PowerShell script to a file, for example, RenameComputers.ps1
.
Create a Package in SCCM:
- Open the SCCM console.
- Go to Software Library > Overview > Application Management > Packages.
- Create a new package and provide details like name, source folder (where your script is saved), etc.
- Add a program for the package, using
powershell.exe -ExecutionPolicy Bypass -File RenameComputers.ps1 -Region <Region> -Building <Building> -Floor <Floor>
as the command line.
- Distribute the package to the desired distribution points. **Deploy the Package**: - Create a deployment for the package targeting the desired collection of computers.
- Add a program for the package, using
- Create a new package and provide details like name, source folder (where your script is saved), etc.
- Go to Software Library > Overview > Application Management > Packages.
Specify Parameters:
- If you're deploying to different sets of machines based on region, building, and floor, you might need multiple deployments with different parameters for each set.
In the SCCM deployment wizard, when specifying the command line for the package, you can include the parameters as follows:
powershell.exe -ExecutionPolicy Bypass -File RenameComputers.ps1 -Region "NA" -Building "B1" -Floor "F1"
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin