VMware Cloud Community
Spartacus75
Contributor
Contributor

Problem script virtual machines creation

Hello everybody,

I come to you for have of your lights about my problem

My script creates 10 virtual machines and configure them (name and IP address).

my problem is my script only create that 3 VMs and stops there, you had an idea?

param($Count,$Name,$Type,$Salle,$Ip)

$Count= $count-1

Connect-VIServer -Server 10.*.*.* -Protocol https -User admin -Password pwd

New-Folder -Name $Salle -Location Salle

  1. 0..$Count | Foreach {

  New-vm -vmhost Server01.london.server.fr -Name "$Name$_" -Template $Type -Location $Salle -Datastore IA015_LN_30

  write-host $count

Start-VM -VM "$Name$_"

write-host "$Name$_"

$VM = Get-VM "$Name$_"

write-host $VM

while ($VM.PowerState -ne "PoweredOn"){

    sleep 5   

$VM = Get-VM $VM

}

write-host "wait"

sleep 60

write-host "$Name$_"

$ESXHost = $VM | Get-VMHost

$secpasswd = ConvertTo-SecureString "format" -AsPlainText -Force

$GuestCred = New-Object System.Management.Automation.PSCredential ("Password", $secpasswd)

Function Set-WinVMIP ($VM, $HC, $GC, $Ip){

$ps1= "C:\WINDOWS\system32\ip.bat $Ip $VM"

#$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++

}

Thanks everybody,

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

You have several Write-Host lines in that script, what do you see on the console when you run the script ?

And how do you call the script ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Spartacus75
Contributor
Contributor

Hello LucD

I execute my script from interface web in wherein I select the number of machine, ip etc.

I remove the write-host.

Reply
0 Kudos
LucD
Leadership
Leadership

Not sure what you mean with "interface web".

But can you leave the Write-Host lines in the script ?

It could give some useful pointers to the possible cause of the problem.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos