Server Build Function issues assigning DNS servers

I have pieced together a server build function. Most of it is working as designed, but recently I’m having an issue assigning DNS addresses, causing domain join to break as well as a whole lot of other stuff that executes past that point. Here are the most relevant portions of the code (it is long, hence me only copying these pieces for now):

     [ValidateScript({$_ -match [IPAddress]$_ })] 
     [ValidateScript({$_ -match [IPAddress]$_ })] 
# Apply IP settings 
Write-Verbose -Message "Applying IP settings to $VMName now." 
$NetworkSettings = "New-NetIPAddress -InterfaceAlias 'Ethernet1' -IPAddress $VMIP -PrefixLength $VMSubnet -DefaultGateway $VMDG" 
Write-Verbose -Message "Getting ready to change IP Settings on VM $VMName." 
Invoke-VMScript -ScriptText $NetworkSettings -VM $VMName -GuestCredential $LocalCred -Verbose 
Start-Sleep -Seconds 30 -Verbose 

# Apply DNS settings 
Write-Verbose -Message "Applying DNS addresses to $VMName." 
$DNSSettings = "Set-DNSClientServerAddress -InterfaceIndex 4 -ServerAddresses ('$VMDNS1','$VMDNS2')" 
Write-Verbose -Message "Getting ready to change DNS Settings on VM $VMName. First a 30 second delay to allow the computer to think." 
Start-Sleep -Seconds 30 -Verbose 
Invoke-VMScript -ScriptText $DNSSettings -VM $VMName -GuestCredential $LocalCred -Verbose 
Start-Sleep -Seconds 30 -Verbose

For some reason, IP address assignment, along with DG and subnet, works as designed, but DNS will not assign properly. I have a piece of script that allows a Write-Verbose statement to verify this, and it is consistently piping out to look like this:

$VMEffectiveAddress = (Get-VM $VMName).guest.ipaddress[0] 
$VMEffectiveDNS1 = (Get-VM $VMName)[0] 
$VMEffectiveDNS2 = (Get-VM $VMName)[1] 
$VMEffectiveDG = (Get-VM $VMName).ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IpAddress | Where-Object {$_ -ne $null} 
Write-Verbose -Message "Assigned IP settings for VM [$VMName] are IP of [$VMEffectiveAddress], Default Gateway of [$VMEffectiveDG] and DNS servers [$VMEffectiveDNS1] and [$VMEffectiveDNS2]."

VERBOSE: Assigned IP settings for VM [VM-Name] are IP of [x.x.x.x], Default Gateway of [x.x.x.x] and DNS servers [fec0:0:0:ffff::1] and [fec0:0:0:ffff::2].

When the DNS servers populate as IPv6, it indicates that DNS did not apply properly. Logging onto the box confirms this. This was working previously on other 2016 servers, and I haven’t changed anything about the function. I’ve sought out help on other forums, and there was some question around why $NetworkSettings and $DNSSettings are encased in double quotes. I have confirmed leaving the double quotes off of $NetworkSettings causes an Invalid Parameter error.

Does anyone have a clue as to what is going on here and why the function fails on me in this spot every time, and what I can do to fix it?

‘$VMDNS1’,’$VMDNS2’ should be “$VMDNS1”,"$VMDNS2" as single quotes will translate to the variable name and not the value in the variable.

And this is probably irrelevant, but is there a reason you use -InterfaceAlias on one cmdlet and -InterfaceIndex on the other? Just a consistency thought.