Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 197835

Re: How to pass parameters in a variable in a loop FOREACH ?

$
0
0

Hello everyone,

 

is there a command to check if the machine is started or not ?

 

I can not solve this problem, my loop of configuration of name and ip address debuted before the machines are started, and therefore, it does not work.

 

I would like my script execute the first two loops, then verifies that the machines are started before execute the last loop, is it possible? I find no solution on this issue.

 

Thank you for your help.

 

Here is my script:

 

 

param($Count,$Name,$Type,$Ip) 
Connect-VIServer -Server 10..*.*.* -Protocol https -User admin -Password admin
2..$Count | Foreach {  New-vm -vmhost 007.london.england.eu -Name "$Name$_" -Template $Type -Datastore Data_base007 } 
2..$Count | Foreach {  Start-VM -VM "$Name$_"} 
read-host "Press Enter" 
2..$Count | Foreach {  $VM = Get-VM "$Name$_"  write-host "$Name$_"  $ESXHost = $VM | Get-VMHost  $secpasswd = ConvertTo-SecureString "formation" -AsPlainText -Force  $GuestCred = New-Object System.Management.Automation.PSCredential ("formation", $secpasswd)  Function Set-WinVMIP ($VM, $HC, $GC, $IP){    $ps1 = "c:\ip.bat $IP $VM"    Invoke-VMScript -VM $VM -HostCredential $HC -GuestCredential $GC -ScriptType bat -ScriptText $ps1  }  Set-WinVMIP $VM $HostCred $GuestCred,$Ip  $Ip++} 

Viewing all articles
Browse latest Browse all 197835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>