cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
pamarovis
Engaged Sweeper

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

2 REPLIES 2
drobertson
Engaged Sweeper III
Add the following action to asset pages:

{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)

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:

$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.
rbutler
Engaged Sweeper
You could do something with PowerShell's Rename-Computer cmdlet.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/rename-computer?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.