I'm trying to use an invoke-vmscript to modify IPV4 parameters on all our servers using their macaddress.
$vms = import-csv C:\temp\adapter_vm.csv -Delimiter ";"
foreach($vm in $vms){
$serveur = $vm.name
$mac = $vm.macaddress
$dns = "$interfaceindex = get-netadapter | where-object MacAddress -Like $($mac) | select-object InterfaceIndex; set-dnsclient -InterfaceIndex $interfaceindex.InterfaceIndex -UseSuffixWhenRegistering $true -RegisterThisConnectionsAddress $true -ConnectionSpecificSuffix test"
Invoke-VMScript -VM $serveur -ScriptType Powershell -ScriptText $dns -GuestUser secret -GuestPassword secret
}
My problem is that the $interfaceindex is not recognized by the remote computer.
set-dnsclient needs the interfaceindex, that is the reason I'm using $interfaceindex.
Could you help me ?
Maybe there is another way ?
Thank you !
----------------------------------------------------------------------------------------
= : The term '=' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:5 + & { = get-netadapter | where-object MacAddress -Like 00-50-56-a1-33-61 | select- ... + ~ + CategoryInfo : ObjectNotFound: (=:String) [], CommandNotFoundEx ception + FullyQualifiedErrorId : CommandNotFoundException
Set-DnsClient : Cannot process argument transformation on parameter 'InterfaceIndex'. Cannot convert value ".InterfaceIndex" to type "System.UInt32[]". Error: "Cannot convert value ".InterfaceIndex" to type "System.UInt32". Error: "Input string was not in a correct format."" At line:1 char:134 + ... InterfaceIndex .InterfaceIndex -UseSuffixWhenRegistering False -RegisterThisConn ... + ~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-DnsClient], ParameterBindi ngArgumentTransformationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-DnsClie nt
$sign.