Changing IP with PowerCLI in Powershell -


i've created script makes clone of vm in vcenter, renames it, changes ip of vm once has powered (from ip of template). having prompt ask ip should be. issue, need enter required ip twice. once label vm, , again change ip of box.

is there way of carrying on variable '$newvmip' entered here:

add-pssnapin vmware.vimautomation.core connect-viserver -server vcenter01 -user myusername -password password1  start-sleep -s 6 $templatevm = "windows qa - 172.30.30.110 - template" $newvmip = read-host "please input ip of new vm" $newvmfor = read-host "please input vm for?" $newvmdate = read-host "please input todays date"  $newvmname = "windows qa - $newvmip - $newvmfor - $newvmdate"  new-vm -name $newvmname -vm $templatevm -vmhost "esx01.coname.local"  move-vm -vm $newvmname -destination testing  start-vm -vm $newvmname  start-sleep -s 200 

to second part of script:

$username = "vmadmin" $password = "password1" $secstr = new-object -typename system.security.securestring $password.tochararray() | foreach-object {$secstr.appendchar($_)} $cred = new-object -typename system.management.automation.pscredential -argumentlist $username, $secstr   invoke-command -computername 172.30.30.110 -scriptblock {  $newvmip = read-host "enter ip" $subnet = "255.255.255.0" $gateway = "172.30.30.1"  netsh int ip set address "local area connection" static "$newvmip" "255.255.255.0" "172.30.30.1"  } -credential $cred 

so don't have enter ip second time?

i assume has second part of script being run on vm/vcenter rather remote location, therefore variable doesn't passed along. have tried specify global variable such $global:newvmip didn't work

thank in advance help.

marc

the 1 important thing missing in second script not passing $newvmip argument. when scriptblock gets called on remote system $newvmip $null.

rough guess need this:

invoke-command -computername 172.30.30.110 -scriptblock {     param($ip)      $newvmip = read-host "enter ip"     $subnet = "255.255.255.0"     $gateway = "172.30.30.1"      netsh int ip set address "local area connection" static "$ip" "255.255.255.0" "172.30.30.1"  } -credential $cred -argumentlist $newvmip 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -