How to Create a Survey with a Custom Button

Modified on Wed, 23 Feb 2022 at 07:37 PM



In this article, we will outline the steps required to setup a User Migration survey to allow the end-users to select their main device from a list of devices currently linked to their profile.

Step 1 - Create the custom field in the User Migrations

In this example, a custom field has been created within Administration ->User Migration->Discovery form(1).

The custom field can be created within any of the custom forms.

  • Click New Field to add in the Customfield.
  • Click Save Changes.
  • Make a note of the Field id of the custom field – e.g 2437


Graphical user interface, text, application, email

Description automatically generated

Step 2 - Create the PowerShell Script

  • Switch to Administration -> User Migrations –> PowerShell Scripts.
  • Copy the following script and ensure the field id is amended to match the id noted in the previous step.

## Get Ids from Script Args

$userId = $ScriptArgs.items[0]

$deviceId = $ScriptArgs.AltItems[0]

## Get Hostname of selected Device

$hostname = Get-MSDevices -DeviceIds $deviceId | Select-Object -ExpandProperty Hostname -First 1

##Save Hostname to a Custom Field

Update-MSUserMigrationsCustomFields -FieldId 2437 -FieldInstanceId $userId -DataValue $hostname

  • Click Save Changes.
  • Make a note of the PowerShell script id. E.g 30

Graphical user interface, text, application, Word

Description automatically generated



Step 3 - Configure the Survey

  • Switch to Administration -> User Migrations ->Surveys (1).
  • Select the desired survey from the survey dropdown menu (2).
  • Click New Field (3) to add fields.
  • Select Links-Devices (4) under the special control column.
  • Enter the following in the Special Control Arg box(5):

Columns:HostName, DeviceType, Make, Model; 

AllowRemove: Yes; 

CascadeRemove: Yes;


CustomButtonLabel: My Main Device;

CustomButtonStyle: btn-outline-info btn-sm;


  • Ensure the CustomButtonScriptId is amended to match the script id noted earlier.


Graphical user interface, text, application, Word

Description automatically generated

  • Click New Field and select the CustomField (6) created within the custom form used to store the information.
  • Click Save Changes to commit the changes (7).



Here’s the output on the Survey

When the User clicks on ‘My Main Device’ Button, it adds the hostname to the my Main Device custom field.

Graphical user interface, application

Description automatically generated

Further Support

If you require further support, please visit ManagementStudio's Service Desk to search the knowledge base or create a new support ticket.