Notification

Icon
Error

Change computer name by custom field

Posted: Tuesday, February 1, 2022 8:19:13 AM(UTC)
pamarovis

pamarovis

Member Original PosterPosts: 1
0
Like
Hello, I am looking for action which would help me rename computers in network. The perfect solution would be rename computer by Custom field(we have "Inventory number"), so we can identify these computers easier and have everything organized. I think this can't be done automatically, so at least pop up should open with input area, and I can submit new computer name.

Thank you in advance,
Dovydas
Wealthyreltub
#1Wealthyreltub Member Posts: 2  
posted: 2/16/2022 9:07:51 PM(UTC)
You could do something with PowerShell's Rename-Computer cmdlet.

https://docs.microsoft.c...uter?view=powershell-7.2

Example 2 is likely what you'd be looking for. Combine that with ShellRunAs if you're not running as a Domain Admin.

I'm not certain how to prompt for input directly out of Lansweeper, so might have to just use Read-Host in the script.
Don
#2Don Member Posts: 33  
posted: 3/4/2022 3:44:08 AM(UTC)
Add the following action to asset pages:

Quote:
{actionpath}Change_Computer_Name.vbs {computer}


Then create a file called "Change_Computer_Name.vbs" and place this in it:
(replace YOUR-SERVER-NAME-HERE with your actual lansweeper server)

Quote:
strCurrentPCName = WScript.Arguments(0)

If strCurrentPCName = "" Then
Wscript.Quit
End If

strNewName = Inputbox("New Computer Name:","Enter the new name for this computer","")

If IsEmpty(strNewName) or IsNull(strNewName) Then
Wscript.Quit
Else

Dim cmd,shell,executor,ps1result,strResult

cmd = "powershell.exe -ExecutionPolicy Bypass -noprofile -command \\YOUR-SERVER-NAME-HERE\lansweeper$\Change_Computer_Name.ps1 '" & strCurrentPCName & "' '" & strNewName & "'"
Set shell = CreateObject("WScript.Shell")
Set executor = shell.Exec(cmd)
executor.StdIn.Close
ps1result = executor.StdOut.ReadAll
strResult = Trim(ps1result)

If IsEmpty(strResult) or IsNull(strResult) Then
Else
Msgbox "Update requested. The changes will take effect after you restart the computer."
End If
End If


Then also create a file called "Change_Computer_Name.ps1" and place this in it:

Quote:
$strCurrentPCName = $args[0]
$strNewPCName = $args[1]

$Credentials = Get-Credential -Message "Enter your Windows admin credentials"

Rename-Computer -ComputerName $strCurrentPCName -NewName $strNewPCName -DomainCredential $Credentials -Force



Then place "Change_Computer_Name.vbs" and "Change_Computer_Name.ps1" in your Lansweeper actions folder.

Active Discussions

Lansweeper Lansweeper Dark Theme
by  mrobbins   Go to last post Go to first unread
Last post: Yesterday at 5:38:01 PM(UTC)
Lansweeper Detect Docking Stations
by  GlenH  
Go to last post Go to first unread
Last post: Yesterday at 3:52:13 PM(UTC)
Lansweeper Exclude non-windows assets from scanning by assetname
by  rapheren   Go to last post Go to first unread
Last post: Yesterday at 1:18:12 PM(UTC)
Lansweeper HTTPS Certifikate untrusted
by  pskup  
Go to last post Go to first unread
Last post: Yesterday at 9:20:07 AM(UTC)
Lansweeper Migrate to new host but without SQL
by  pskup   Go to last post Go to first unread
Last post: Yesterday at 9:03:14 AM(UTC)
Lansweeper Object reference error after updating to 10.2.0.0
by  Erik.T  
Go to last post Go to first unread
Last post: Yesterday at 8:10:25 AM(UTC)
Lansweeper Custom reporting - Asset Groups and AD Description
by  rbshawn   Go to last post Go to first unread
Last post: 6/29/2022 10:54:10 PM(UTC)
Lansweeper A FIX for an odd Scan Error WMI/DCOM from scanning server
by  danielm  
Go to last post Go to first unread
Last post: 6/29/2022 10:14:44 PM(UTC)