I have a script that modifies network info of certain VMs ,however it run sequentially . Since there are hundred of VMs , I want to all VMs to execute the command simultaneously in order to save time . Also how do I add invoke-vmscript to the scriptblock with external variables. I did try few things but doesnt seem to working well. Script is run on a system using powercli 10 on linux and no additional modules are allowed to be installed
Below is the code , any help would be much appreciated
$test=get-vm -name testvm* |sort-object
$fip='192.168.10.41'
$f=$fip.Split(".")|select -first 3
$s=[system.String]::join(".",$f)
$l=$fip.Split(".")|select -last 1
foreach ($vm in $test) {
Write-Host "$vm $s.$l"
do {start-sleep -s 2; write-host " $vm not ready yet" ; $tstatus=(get-vm
$vm).extensiondata.Guest.ToolsStatus;}while($tstatus -ne "toolsOk");
invoke-vmscript -ScriptText "sed -i '14,20 d' /etc/network/interfaces" -
ScriptType bash -VM $vm -GuestUser admin -GuestPassword Welcome!}
$ipscript = "sed -i -e 's/address *.*.*.*/address $s.$l/g'
/etc/network/interfaces"
write-host " Adding IP "
invoke-vmscript -ScriptText $ipscript -ScriptType bash -VM $vm -GuestUser
$GuestUserName admin -GuestPassword Welcome!
Start-Sleep -s 2
Restart-VM -VM $vm -RunAsync -Confirm:$false
$l=[int]$l+1
}