title: Powershell - Invoke-VMScript - How to insert a variable into the script variable?
body: <p>I'm trying to use an invoke-vmscript to modify IPV4 parameters on all our servers using their macaddress.</p>
  
  <pre><code>$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
  
  }    
  </code></pre>
  
  <p>My problem is that the $interfaceindex is not recognized by the remote computer.</p>
  
  <p>set-dnsclient needs the interfaceindex, that is the reason I'm using $interfaceindex.</p>
  
  <p>Could you help me ?</p>
  
  <p>Maybe there is another way ?</p>
  
  <p>Thank you !</p>
  
  <pre><code>----------------------------------------------------------------------------------------
  </code></pre>
  
  <p>= : 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
   + &amp; { = get-netadapter | where-object MacAddress -Like 00-50-56-a1-33-61 |
   select- ...
   +     ~
       + CategoryInfo          : ObjectNotFound: (=:String) [], CommandNotFoundEx
      ception
       + FullyQualifiedErrorId : CommandNotFoundException</p>
  
  <p>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</p>