anyway, assuming the invoke-vmscript is working i have no idea how to fix my changing ip issue.
I have a table with the source IPs and the destination IPs.
I imagine the correct method is to do a foreach loop of my VMs to modify and apply the modification to each one with something like that?
iptables.json :
[{"ipsource":"10.0.0.1","ipdest":"10.20.0.1},
{"ipsource2":"10.0.0.2","ipdest2":"10.20.0.2}]
$importJSON = Get-Content c:\iptables.json | ConvertFrom-Json
$IPtables = @{}
foreach ($thisIP in $importJSON)
{
$IPtables.add($ThisIP.ipsource,$ThisIP.ipdest)
}
$testVMs = get-vm -Location $folderofVMs
foreach ($thisVM in $testVMs)
{
foreach ($thisIP in $importJson.ipsource)
{
$script = '(get-netipaddress | where-object {$_.IPaddress -match "' + $thisIP + '"-and $_.AddressFamily -eq "IPv4"}).IPAddress'
$sourceIP = invoke-vmscript -scripttext $script -vm $thisVM
if ($sourceIP -eq $thisIP)
{
$script2 = $changingIP = '%WIWNDIR%\system32\netsh.exe interface ipv4 set address name = "Eth0" source=static address=' + $IPTables[$sourceIP] + 'mask=255.255.255.0 gate
}
}
}