As for the Windows computers that need an external ethernet adaptor, I took a powershell script the FOG team made and added some lines to lookup the HP computer by serial and update the primary MAC to the HP MAC instead of the adaptor to avoid the “computer already exists” problems. When this is working, I leave the computer on the same adaptor until it’s all imaged and joined to my AD domain before moving the adaptor to another computer to start another image, at which point the script should have fixed the MAC address in the FOG database.
I believe you have to install the FOG powershell API in the base image, and then have this powershell script run after sysprep. I use the Setupcomplete.cmd method by putting a cmd file in %WINDIR%\Setup\Scripts. On an HP, I make sure and have the MAC Address Manager app installed and the service is running before the API script runs.
NOTE I have not used this method since FOG 1.5.6. I’m trying to get my servers updated with 1.5.10.
Setupcomplete.cmd:
Start "Starting HP Services" /wait /separate /realtime CMD /C c:\windows\system32\sysprep\services.cmd
Start "Updating MAC Address" /wait /separate /realtime CMD /C powershell -executionpolicy bypass -file c:\windows\system32\sysprep\macupdate.ps1
exit
services.cmd
for /F "tokens=3 delims=: " %%H in ('sc query "HPMAMSrv" ^| findstr " STATE"') do (
if /I "%%H" NEQ "RUNNING" (
net start "HPMAMSrv"
timeout /nobreak 3
)
)
macupdate.ps1
<#
This script updates the primary MAC address in the FOG database POST sysprep. This is for computers that use the Host-Based-MAC-Address
feature to overwrite the MAC address of an attached ethernet dongle (ie the HP x360 which does not have an integrated NIC.)
Invoke-FogApi written by the FOG development team. Updated 9-26-2017.
#>
function Invoke-FogApi {
<#
.SYNOPSIS
a cmdlet function for making fogAPI calls via powershell
.DESCRIPTION
takes a few parameters with a default that will get all hosts
Makes a call to the api of a fog server and returns the results of the call
The returned value is an object that can then be easily filtered, processed, and otherwise manipulated in poweshell.
i.e. you could take the return value of the default all hosts and run
$(invoke-fogapi).hosts | where name -match "$(hostname)"
to get the host information for the current computer
.PARAMETER fogApiToken
a string of your fogApiToken gotten from the fog web ui. Can be set in the function as a default or passed to the function
.PARAMETER fogUserToken
a string of your fog user token gotten from the fog web ui in the user section. Can be set in the function as a default or passed to the function
.PARAMETER fogServer
The hostname or ip address of your fogserver, defaults to the default fog-server
.PARAMETER uriPath
Put in the path of the apicall that would follow http://fog-server/fog/
i.e. 'host/1234' would access the host with an id of 1234
.PARAMETER Method
Defaults to 'Get' can also be
.PARAMETER jsonData
The jsondata string for including data in the body of a request
.EXAMPLE
#if you had the api tokens set as default values and wanted to get all hosts and info you could run this, assuming your fogserver is accessible on http://fog-server
Invoke-FogApi;
.Example
#if your fogserver was named rawr and you wanted to put rename host 123 to meow
Invoke-FogApi -fogServer "rawr" -uriPath "host/123" -Method "Put" -jsonData "{ `"name`": meow }";
.Link
https://news.fogproject.org/simplified-api-documentation/
.NOTES
The online version of this help takes you to the fog project api help page
#>
[CmdletBinding()]
param (
#took out my api tokens, you can default apitoken strings here or pass them to the function
[string]$fogApiToken = 'token...',
[string]$fogUserToken = 'token...',
[string]$fogServer = "x.x.x.x",
[string]$uriPath = "host", #default to get all hosts
[string]$Method = "Get",
[string]$jsonData #default to empty
)
begin {
# Create headers
Write-Verbose "Building Headers...";
$headers = @{};
$headers.Add('fog-api-token', $fogApiToken);
$headers.Add('fog-user-token', $fogUserToken);
# Set the baseUri
Write-Verbose "Building api call URI...";
$baseUri = "http://$fogServer/fog";
$uri = "$baseUri/$uriPath";
}
process {
Write-Verbose "$Method`ing $jsonData to/from $uri";
if ($Method -eq "Get") { #don't include body with get
$result = Invoke-RestMethod -Uri $uri -Method $Method -Headers $headers -ContentType "application/json";
}
else {
$result = Invoke-RestMethod -Uri $uri -Method $Method -Headers $headers -Body $jsonData -ContentType "application/json";
}
}
end {
Write-Verbose "finished api call";
return $result;
}
}
# Get MAC addresses of local ethernet adapters, should return only the live (plugged into switch and lit) ethernet MAC.
# Will fail if no live adapters found or more than one found. Should ignore WiFi.
$colItems = get-netadapter | where {$_.name -like "ethernet*" -and $_.status -match "up"} | select -expandproperty macaddress
$c = 0;
foreach ($objItem in $colItems) {
$c++;
$hostMAC = $objItem;
}
if ($c -ne 1) {exit;}
# Remove dashes from get-netadapter for simple match later. Replace the dashes in the MAC with colons, and make lower case for FOG format.
$hostMACsimple = $hostMAC -replace '-','';
$hostMAC = $hostMAC.ToLower() -replace '-',':';
# Grab the computer serial number from the BIOS, really only works on brand name computers.
$theserial = gwmi win32_bios | select -expandproperty serialnumber
if ($theserial -eq $null) {exit;}
# Find the database host id number on the FOG server.
$hostId = ((Invoke-FogApi -uriPath "inventory").inventorys | Where-Object sysserial -match "$theserial").hostID;
if ($hostId -eq $null) {exit;}
# With the host id get the primary mac association that matches that host id.
$primacitem = (Invoke-FogApi -uriPath "macaddressassociation").macaddressassociations | Where-Object {$_.hostID -match "$hostId" -and $_.primary -eq 1};
$primac = ((Invoke-FogApi -uriPath "macaddressassociation").macaddressassociations | Where-Object {$_.hostID -match "$hostId" -and $_.primary -eq 1}).mac;
if ($primac -eq $null) {exit;}
$primac = $primac -replace ':','';
# If the MACs are different, update the fog database
if ($hostMACsimple -match $primac) {exit;} else {
$primacitem.mac = $hostMAC;
Invoke-FogApi -jsonData ($primacitem | ConvertTo-Json) -Method "Put" -uriPath "macaddressassociation/$($primacitem.id)/edit";
}