Rename-Computer via SCCM

We need to rename ~500 endpoints in our environment. Due to politics, not all devices have PSRemoting enabled. That said, they all have the SCCM agent configured. I am thinking of having a CSV for all endpoints to reference, and if their name is found, rename to the specified new entry. For example, the CSV file would contain something like this:

Old New
OLD1234 NEW2345
ABC2345 ABC1234

My thought is to have the script import the CSV file, then run the rename command. My main question is on the line $Obj = $Devices | Where-Object {$_.Old -eq $env:COMPUTERNAME}. I’m not sure if there is a better way to find/select the row and specifically the ‘New’ column of that row. I’d love to see how others may handle this. The very beginning I’ve got thus far is this:

# Import device list $Devices = Import-Csv C:DeviceList.csv If($Devices.Old -contains $env:COMPUTERNAME){ Try{ $Obj = $Devices | Where-Object {$_.Old -eq $env:COMPUTERNAME} $NewName = $Obj.New.ToString() Rename-Computer $NewName -Restart } Catch { # Error handling of some sort } } 

Edit: Reddit formatting

submitted by /u/gorlechov
[link] [comments]

Leave a Reply