Skip to content

rename_workstation_auto.ps1

Corey Watson edited this page Dec 19, 2025 · 1 revision

rename_workstation_auto.ps1

Automatically rename Windows workstation and sync to SuperOps using CLIENT3-USERUUID pattern.

Overview

Rename a Windows device and sync the same name to SuperOps.

Naming (Windows-legal; max 15 chars; no trailing hyphen):

  • CLIENT3-USERUUID
    • CLIENT3 : 3-char abbreviation of $YourClientNameHere (always forced).
    • USER : Sanitized username; maximized; truncated if needed.
    • UUID : SMBIOS UUID tail; at least 3 chars; trimmed to fill exactly 15.

Notes:

  • Only A–Z, 0–9, and hyphen used.
  • Name never starts or ends with '-'.
  • Always exactly 15 chars.
  • SuperOps asset name is updated to match.

Purpose

Rename a Windows device and sync the same name to SuperOps. Uses automatic 3-character client abbreviation generation from the client name placeholder.

Prerequisites

  • PowerShell 5.1 or later
  • Administrator privileges required
  • SuperOps module available
  • Internet connectivity for SuperOps API calls

Configuration

Required Inputs

  • Runtime: $YourApiKeyHere
  • Placeholders: $YourAssetIdHere, $YourClientNameHere, $YourAssetNameHere

Settings

  • $SUPEROPS_API_KEY : SuperOps API key (injected at runtime)
  • $SUPEROPS_SUBDOMAIN : "limehawk" (hardcoded)
  • $ASSET_ID : Asset ID placeholder
  • $ASSET_NAME_PLACEHOLDER : Asset name placeholder
  • $CLIENT_NAME_INPUT : Client name placeholder
  • $MaxUserSegmentLen : 8 (maximum username segment length)
  • $MinUuidSuffixLen : 3 (minimum UUID suffix length)
  • $MaxHostLen : 15 (maximum hostname length)

Data Sources & Priority

  1. Hardcoded values (SuperOps subdomain, length constraints)
  2. Runtime placeholders (API key, asset ID, client name)
  3. System information (CIM)
  4. SMBIOS UUID
  5. SuperOps GraphQL API

Behavior

  1. Validates SuperOps variables and system information
  2. Extracts 3-character client abbreviation from client name
  3. Sanitizes logged-in username
  4. Constructs CLIENT3-USERUUID hostname (exactly 15 characters)
  5. Checks if current hostname already matches desired name
  6. Renames Windows computer if needed
  7. Updates SuperOps asset name via GraphQL API
  8. Reports success or handles benign rename errors

Security Notes

  • API key is injected at runtime, not hardcoded
  • No secrets logged to console
  • Uses HTTPS for SuperOps API calls
  • Validates hostname format before applying

Exit Codes

  • 0: Success
  • 1: Failure (validation error, API error, or rename failure)

Example Output

[ SUPEROPS VARIABLES ]
--------------------------------------------------------------
AssetId (placeholder)    : 12345
AssetName (placeholder)  : OLD-NAME
ClientName (placeholder) : Example Client Inc
Subdomain (hardcoded)    : limehawk
MaxUserSegmentLen        : 8

[ RAW SYSTEM VALUES ]
--------------------------------------------------------------
ENV USERNAME             : jdoe
CIM UserName             : DOMAIN\jdoe
Current HostName (CIM)   : OLD-HOSTNAME
SMBIOS UUID              : 12345678-ABCD-EFGH-IJKL-MNOPQRSTUVWX

[ DERIVED SEGMENTS ]
--------------------------------------------------------------
CLIENT SEGMENT           : EXA
USER SEGMENT             : JDOE
DESIRED/OS NAME          : EXA-JDOE1234567
Name Length              : 15

[ RENAME ACTION ]
--------------------------------------------------------------
CURRENT NAME(S)          : OLD-HOSTNAME
STATUS                   : RENAMING

[ SUPEROPS UPDATE ]
--------------------------------------------------------------
Updating asset name in SuperOps...
GraphQL Success

[ RESULT ]
--------------------------------------------------------------
Status                   : SUCCESS

Version History

  • v8.2.1 (2024-12-01) Fixed StrictMode error checking GraphQL response for errors.
  • v8.2.0 (2025-08-20) Clarified README: auto script enforces 3-char client code.
  • v8.1.0 (2025-08-19) Pattern CLIENT-USERUUID, min UUID=3, maximize USER, exact 15.
  • v8.0.x (2025-08-19) No separators prototype, experimental.
  • v7.4.1 (2025-08-19) Fixed PS5.1 syntax issues; removed ternary shorthand.
  • v7.4.0 (2025-08-19) Added benign rename error handling; canonical name check.
  • v7.3.x (2025-08-19) Added full README in Style A; standardized headers.
  • v7.2.x (2025-08-19) Brand segment always first word; UUID always appended.
  • v7.0 (2025-08-19) Structured diagnostics improvements.
  • v6.x (2025-08-19) Split branch from manualname; preserved 3-char client.
  • v5.x (2025-08-19) CLIENT/BRAND/USER baseline pattern; SuperOps sync.
  • v4.x (2025-08-19) Added GraphQL mutation to update SuperOps asset.
  • v3.x (2025-08-19) Introduced sanitization helpers & diagnostics.
  • v1–2.x (2025-08-19) Early rename iterations (no SuperOps sync).

Links

Clone this wiki locally