Hola / hi Marco,
1. Edit your post and remove all the password, IP and domain specific information.
2. Don't use your domain admin account to log into vcenter set up a different account specifically for vcenter
3. Don't use IP addresses in the script use DNS names - IP address change DNS name not so must.
4. Don't store your password in the script. Store it encrypted on the pc you are running the script from.
-----------------
#STORING CREDENTIAL in a SECURE STRING and then using later
read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt` ###this has to be run as the user the schedule task will be ran as#####
#This will prompt you for the paasword and store it in securestring.txt
#this is not part of your main script this is done only once to store the password
----------------
Then use this in the script
$vcenter_pwd = cat C:\SecureString.txt | ConvertTo-SecureString
5 to answer this:-
"Now what stuck me is that I'm not sure how to do so that cloning is generated every week but does not eliminate the already cloned machine that is generated as a new clone"
simples :smileyhappy: : delete the old clone first before recreating the new clone,
So finally your script looks like this
------------------------------------------------
##Clonar VM
##Variables
$vcenter_server ="I would use dns name"
$vcenter_user ="administrator@domainl"
$vcenter_pwd = cat C:\SecureString.txt | ConvertTo-SecureString
$Hostesxi = "i would use dns name"
$VMsource = "Ubuntu"
$VMclone = "Ubuntu-clone"
##Connect to vCenter
connect-viserver -server $vcenter_server -User $vcenter_user -Password $vcenter_pwd
#Eliminar clonada antiguo
Get-VM -Name $VMclone | Remove-VM -DeletePermanently -Confirm:$false
##Clone VM, disco virtual tipo thick y carpeta de almacenaiento de la VM
New-VM -VM $VMsource -Name $VMclone -VMHost $Hostesxi -DiskStorageFormat Thick -Location "Laboratorios" -Notes "Clone creado $dateofclone by Marco Lopez"
##Desconect Network Adapter source VM
Get-VM $VMsource | Get-NetworkAdapter | Set-NetworkAdapter -connected:$false -startconnected:$false
##Iniciar VM clonada
GET-VM -Name $VMclone| Start-VM -Confirm:$False
----------------------------------------------------------------------
6. use Windows task scheduler to run this task weekly/monthly to RUNAS account that stored the password in step 4, select "run whether user logged on or not", and check "run with highest privileges" - it doesn't have to be the same account that is logging onto vcenter. The powercli modules etc will have to be installed on that pc that your are running the schedule on.
I hope this helps
Alex