I’m trying to standardize hostnames on all of our PCs. We aren’t using AD, just local users. We have a standard for our hostnames to be “company-lastname-pc”… from what I understand WIN local users don’t have the concept of a last name. I’m wondering if there is anyway to pass in some sort of meta data from automox to the worklet so I can automate this. I would obviously need to tag the user in automox with their last name somehow… just wondering if this is doable.
I’m thinking best option is if the local user account has the last name that could be parsed with some powershell magic.
For example let’s say a local user is jack.smith
# Company
$company = 'Contoso'
# Query Actively Logged in user
$user = (quser | select -Skip 1 | foreach { ($_ -split " ")[0] }).replace(">","")
# Get Last Name
$lastname = $user.split('.')[1]
# Rename Computer
Rename-Computer -NewName "$($company)-$($lastname)-pc" -Force
If you go the API route and want to pull a tag from each machine. This script assumes only one tag exists and you have less than 500 agents in Automox.
# Company name
$company = 'Contoso'
# API and Header
$apiKey = "INSERT API KEY HERE"
$apiUrl = "https://console.automox.com/api/servers/"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $apiKey")
# API to get first 500 Automox Agents
$response = Invoke-RestMethod $apiUrl -Method 'GET' -Headers $headers -Body $body
$response | ConvertTo-Json
# Get Tags for Computer
$currentMachineName = $env:COMPUTERNAME;
foreach($server in $response){
$name = $server.name;
if($currentMachineName -eq $name){
$lastname = $server.tags
}
}
# Rename Computer
Rename-Computer -NewName "$($company)-$($lastname)-pc" -Force
Reply
Login to the community
No account yet? Create an account
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.