cancel
Showing results for 
Search instead for 
Did you mean: 

Windows: Command for bound username+serial (or something else) to hostname script

JuergenKlaassen
Rising Star I
Rising Star I

Hi

I came across a question yesterday to have @Fulgubbe 's script for Windows as well.
So i gave it a shot right now to construct a similar (not equivalent) approach for Windows-devices:

# JC API Key
$JCAPIKEY = '<YOUR API KEY HERE>'

# Install and import the JumpCloud Powershell Module
Write-Host "Installing the JumpCloud PowerShell Module" -BackgroundColor Black -ForegroundColor Cyan
Install-Module -Name JumpCloud -Force

# Connect to the JumpCloud API
Write-Host "Connecting to the JumpCloud API" -BackgroundColor Black -ForegroundColor Cyan
Connect-JCOnline $JCAPIKEY

# Acquire SystemID from jcagent.conf
Write-Host "Acquiring the System ID" -BackgroundColor Black -ForegroundColor Cyan
$agentconf = Get-Content "C:\Program Files (x86)\JumpCloud\Plugins\Contrib\jcagent.conf" | ConvertFrom-Json
$agentconf.systemKey

# Get the system and systemuser objects
$system = Get-JCSystem -SystemID $agentconf.systemKey
$systemuser = Get-JCSystemUser -SystemID $agentconf.systemKey
$system.serialNumber
$systemuser.Username

# Create the hostname
$hostname = $systemuser.Username+"-"+$system.serialNumber
$hostname

# Set the hostname
Write-Host "Setting the hostname" -BackgroundColor Black -ForegroundColor Cyan

#Set-ComputerName -ComputerName $hostname
Set-JCSystem $agentconf.systemKey -displayName $hostname

One important note: 
Not reflected in this script yet, but I'd recommend to have the API-key stored in a file attached to the command and then read it from there for execution. By having it in a file attached, it won't surface in the Command Results post execution and therefore limits the risk of potential exposure. Important then is - of course - also to remove the file from the host at the end of the script. 

Have a great weekend ahead
- Juergen

1 REPLY 1

ncarmichael
Rising Star I

This great Juergen 🙂

Most Windows machines will be 64-bit know so it would be worth having the script also check "C:\Program Files\JumpCloud\Plugins\Contrib\jcagent.conf" too

 

Keep up the good work,

Neil

You Might Like

New to the site? Take a look at these additional resources:

Community created scripts:

Our new Radical Admin blog:

Keep up with Product News:

Read our community guidelines

Ready to join us? You can register here.