Rename multiple devices

MM
Miguel Machado
CodeOne - MSP

Hello, I need to rename more than 1000 Android devices(all in the same device group) and obviously I don't want to rename them one by one.

Is there any way I can rename multiple devices at once?

Currently, my devices has names like this:

XX-123-YY1

ZZ-456-BB2

...

And I need to change the middle part to 4 digits, like this:

XX-0123-YY1

ZZ-0456-BB2

...

Thanks.

2 years ago
Android
ANSWERS
RC
Raymond Chan Diamond Contributor
2 years ago

You can first check if the SET SUBSTRING legacy script command works for the device agent version(s) you are using on your targeted device(s).  E.g.

set P1=substring %devicename% 1 3

set P2=substring %devicename% 4 3

set P3=substring %devicename% 7 4

log   -i   "%devicename%  -  P1:%P1%  P2:%P2%  P3:%P3"

If so, try sending the following script to your test device to see if it works:

set P1=substring %devicename% 1 3

set P2=substring %devicename% 4 3

set P3=substring %devicename% 7 4

devrename  %P1%0%P2%%P3%

After sufficient successful test results, you can try sending the script at device-group level.

MM
Miguel Machado
2 years ago

Hello Raymond,

I try to run this command to check if SET SUBSTRING legacy script command works but I don't know what result I should expect.

set P1=substring %devicename% 1 3
set P2=substring %devicename% 4 3
set P3=substring %devicename% 7 4
log   -i   "%devicename%  -  P1:%P1%  P2:%P2%  P3:%P3"

What should happen after I run this script? The device needs to be online to make this test?

Best Regards, Miguel Machado

MM
Miguel Machado
2 years ago

Hello Raymond, I junt found where I can see log message.

I have this message so substring don't work.

 

RC
Raymond Chan Diamond Contributor
2 years ago

The legacy script commands mentioned in the previous post I sent out last midnight may not be supported by recent device agents any more.

This morning, I successfully put together the  4-5 lines of javascript  (e.g.  the mobicontrol.device class and string function)  required to do the same parsing & new name formation tasks as the legacy script does.  Unfortunately, the final function (or javascript class method) to do the device renaming seems to be missing based on the latest online javascript API's documentation. 

So, the remaining option left for such smart bulk renaming operation is likely be doing it with REST API calls, which required many fold of lines of codes to perform  the task.

MM
Miguel Machado
2 years ago

I really like the previous solution.

There is a new command that replaces SUBSTRING or other way of make a substring?

Where I can see a list of all available commands?

RS
Rafael Schäfer
2 years ago

If you are familar with Sotis API, then you can do it via API calls alternatively.

Or if those devices named based on a ini-file (using custom data) then a combination of Legacy and Javascript can do the trick also (reworking ini file via javascript and sending out the legacy renaming script afterwards).

Did this in hte past for all our devices.

MM
Miguel Machado
2 years ago

Hello Rafael,


Unfortunately the devices named is not based in a ini-file.

I'm not familiar with SOTI API but I take a look and from what I could understand we need to create an API client key with MCAdmin.exe and right now I don't have access to SOTI instalation server to create this necessary key.

Best Regards, Miguel Machado

MM
Miguel Machado
2 years ago

Hello Rafael,

Today I ran some tests in our test environment and I created an API Key with success.

Now I am trying to understand how I can rename one device via API, but I can't find the API call I should make.

Could you help?

RC
Raymond Chan Diamond Contributor
2 years ago

Hi Miguel,

If you already have or can quickly generate a spreadsheet with the device-ID and current device name of each device to be renamed, then  you can achieve the task with the followin steps:

1.  Add two new columns with the new device names required and a custom attribute (e.g. "NewName").  Each device that need not be renamed can have its new-name field the same as its existing name..

2  Only keep the three required columns in the right order in the spreadsheet and have it exported as a CSV file 

3. Perform bulk import of the new MobiControl custom attribute "NewName" with the CSV file

4. Run the script

      devrename  %CustomAttr:NewName%

   at the required device-group level.

While this approach is much more work than the short no-brainer parser-oriented script mentioned in earlier posts, this approach only involves one CSV file on the server/web-console side, and should be much simpler and more secure than the per-device .ini file approach mentioned by Rafael.

RS
Rafael Schäfer
2 years ago

Why is an ini file not secure if you already used it for naming devices individually?
And even this was only a tipp IF his devices got this information using ini file, if not, this isn't a possible way for him.

And the only bad thing on those is, that the device has to be online and you need the second (legacy) script to rename the device.

But this very depends on how you did the naming before. And i definitely think "not secure" is the worst description on this. I would agree if you would say "it' not the best way" to do it.

MM
Miguel Machado
2 years ago

Hello Raymond,

I have a few concerns with this solution.

How can I have certain that upload a csv file with custom attributtes don't bring problems to other devices (from other device groups) if I need to upload this file to all devices. 

Can I upload this to only one group of devices?

RC
Raymond Chan Diamond Contributor
2 years ago

The approach of renaming a device based on an ini file on each remote device  physically accessible by dumb end-users/hackers is INHERENTLY less secure than using a centralized file/way on  secured server side which is supposedly behind firewalls and monitored/managed by IT professionals.  That is common sense.   Also, LESS secure does not imply  INSECURE.  I have never said what other way is "not secure".

RC
Raymond Chan Diamond Contributor
2 years ago

Hi Miguel,

The CSV file for custom attribute import is processed in a per-line basis (with device ID, custom attribute name and custom attribute value on each line),  and one is free to include any combinations of attributes of any devices from any device/devices of the same or different  device group/groups in a CSV file.  If I remember correctly, each CSV import file is limited to a maximum of 2000 lines.

Thus, you can of course choose to upload to only one group of devices, and run the devrename script command to that group only.   If you have say three devices in that device group that you don't want to rename, then you should have three lines in the CSV import file that specify those three devices with the custom attribute value set the same as the existing name, such that the devrename script subsequently applied to the whole device group will effectively make no change to the names of the three devices. 

This of course involve extra effort to avoid incorrectly renaming devices that are not targeted, which is exactly the reason why I said the parser-based script, if functional with all required commands available, is much simpler to complete the task. 

In any case,  I will file feature request to Soti to implement RENAME and other common operations in their future Javascript engine.

RC
Raymond Chan Diamond Contributor
2 years ago

Hi Miguel,

I don't know why I couldn't see SOME of your reply posts in the last two days.

I've just noticed that you asked about javascript command set.  The official Soti online documentation can be found at https://www.soti.net/mc/help/javascriptapi/en/index.html

Also, regarding creation of  API client key with MCAdmin.exe, if your MobiControl  server is a cloud instance, I think you can just email Soti support team to create one for you.  

MM
Miguel Machado
2 years ago

Hello Raymond,

First off, thank you for all your replies.

Our MobiControl server is not a cloud instance and currently I don't have access to SOTI Server.

If I can't use the legacy commands because Substring doesn't work (I don't really understand why this doesn't work despite being in the latest version of the documentation).

So, my only option is to use the approach with a csv file.

I have a few questions about this approach:

  • First of all I need to show only deviceId and deviceName and export as CSV?
  • When you say that I need to add two new columns with the new device names required and a custom attribute (e.g. "NewName") where should I add these columns? My exported csv file?
EG
Edgar Gomez
2 years ago

Hello Miguel,

You must create a custom attribute, Newname, in Mobicontrol.

Import the new name data from a csv file, and then send the script to the devices:

  devrename %CustomAttr:NewName%

With this, each device will change the name to the value that has been set in the NewName attribute


The csv file must have this in the first line:

DeviceID,AttributeName,AttributeValue

In the other lines
The AttributeName column will always be NewName
The AttributeValue column is the name you want to give the device

https://www.soti.net/mc/help/v15.4/en/console/reference/dialogs/import_custom_attributes.html

I hope this helps.