探花大神

Automate Device Primary User Assignment with PowerShell

This article walks through how to us a PowerShell script to automate assigning primary users to your devices in 探花大神. The script analyzes all devices and identifies which of them are eligible to have a primary user automatically assigned. It also allows you to specify exclusions for certain usernames (such as administrator and guest accounts) as part of an ignore list. Before making changes, a summary report is generated for review and confirmation.

Prerequisites:

  • You must have an API key to authenticate before running the script. See 探花大神 APIs for more information.
  • You must have an Administrator role in 探花大神 to be able to run the script.
  • The script requires PowerShell 5.1 or higher.
  • The 探花大神 PowerShell Module must be installed, and it must be version 2.18.0 or higher.
    • If not installed, open PowerShell as an Administrator and run Install-Module -Name 探花大神 to install.

Considerations:

  • The script will only propose assigning a primary user if specific conditions are met:
    • A primary user will be assigned when:
      • The device has one user directly bound to it who is not on your ignore list.
      • The device has multiple users directly bound to it, but only one user remains after applying the ignore list.
    • A primary user will not be assigned when:
      • The device already has a primary user assignment.
      • The device has no bound users.
      • Users are not directly bound to the device (for example, users bound to the device from a user group are indirectly bound).
      • Multiple eligible users remain after applying the ignore list.
      • An eligible user on the device is also on the ignore list.

Running the Assign Primary User Script

Step 1: Download and Run the Script

  1. Download the from 探花大神.
  2. Save it as a .ps1 file (e.g., Assign-PrimaryUsers.ps1).
  3. Open PowerShell, navigate to the file's location, and run it: .\Assign-PrimaryUsers.ps1

Step 2: Connect to 探花大神

The script prompts for your API key to connect to 探花大神. You will then be asked if you want to use a different key or provide an Organization ID (for multi-tenant portals), which is useful for switching between organizations.

Step 3: Provide the User “Ignore List”

Next, you'll be prompted to enter an ignore list. This prevents admin or service accounts from being assigned as a primary user.

Enter a comma-separated list of usernames to ignore... or press Enter to skip

  • Enter usernames separated by commas (e.g., admin,jdoe,service-account).
  • The script checks if each username exists. If any are invalid, you will be notified and asked to enter the list again.
  • Press Enter to skip this step.

Step 4: Analysis

The script analyzes each device in your organization, checking user bindings, the ignore list you provided, and any existing primary user assignments. A progress bar displays.

Step 5: The CSV Report

After the analysis, a CSV report of all devices is generated. You will be prompted to choose a save location.

  • Press Enter to save the file to the Desktop.
  • You will then be asked if you want to open the report.

Important:

Review the report carefully before proceeding.

The generated CSV is your tool for reviewing all proposed changes:

  • SystemID: The system's unique 探花大神 ID.
  • SystemHostname: The hostname of the system.
  • SystemDisplayname: The system's display name in 探花大神.
  • AssociatedUserCount: Total number of users associated with the device.
  • ProposedPrimaryUserEmail: The email of the proposed primary user. This field displays "No Primary User can be assigned" if no candidate was found.
  • ProposedPrimaryUsername: The username of the proposed primary user. This field displays "No Primary User can be assigned" if no candidate was found.
  • Reason: A clear explanation of each device's status and why a user was or was not proposed for assignment.

Step 6: Final Confirmation

The script will state how many devices are eligible for an update and ask for final confirmation before making any changes.

Found N systems to update. Do you want to assign these users as primary users? (y/n)

  • Enter y to proceed.
  • Enter n to exit safely without making changes.

Step 7: Review the Final Summary

The script will end by displaying a summary of its findings and actions in the PowerShell Terminal.

Assigned primary users are reflected in the 探花大神 Admin Portal devices list. You may need to add the Primary User column to the list view to see this information.

Back to Top

List IconIn this Article

Still Have Questions?

If you cannot find an answer to your question in our FAQ, you can always contact us.

Submit a Case