Hi Luc,
1) I have tried to save the password in script itself password saved in executed path but its not running properly
2) Also i have tried using task scheduler to schedule the task help of following link (Schedule PowerCLI script in Windows task scheduler » VCDX56)
Its not working properly
3) I have doubt in that action tab which path should i choose in start program path and argument path.
I have attached modified script. Can you please correct me where i did mistake.
Connect-VIServer xx.xx.xx.xx
$vmName = 'MC-D-Mifos01'
$cloneName = "$($)Varnikmail_Backup_$((Get-Date).ToString('MMddyyyy'))"
$oldCloneName = "$($)Varnikmail_Backup_$((Get-Date).AddDays(-7).ToString('MMddyyyy'))"
$ds = Get-Datastore | where{$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess} |
Sort-Object -Property FreeSpaceGB -Descending | select -First 1
$esx = Get-Cluster -VM $vmName | Get-VMHost | Get-Random
$start = Get-Date
Get-VM -Name $oldCloneName -ErrorAction SilentlyContinue |
Remove-VM -DeletePermanently:$true -Confirm:$false
$vm = New-VM -VM $vmName -Name $cloneName -Datastore $ds -VMHost $esx
$cloneEvent = Get-VIEvent -Entity $vm -Start $start |
where{$_ -is [VMware.Vim.VmClonedEvent] -and $_.Vm.Vm.Value -eq $vm.ExtensionData.MoRef.Value}
$cred = Get-Credential -Message "Credentials for mail server"
$pwd = Get-Content c:\vSphere\scripts\powerclicred | ConvertTo-SecureString
$cred = New-Object System.Management.Automation.PsCredential “mssi\sasai“, $pwd
$sMail = @{
To = 'asuresh@msservicesinc.com'
From = 'asuresh@msservicesinc.com''nsiva@msservicesinc.com'
Subject = 'Clone Report'
BodyAsHtml = $true
Body = $Clone Report | Out-String
SmtpServer = 'smtp.1and1.com'
UseSsl = $true
Credential = $cred
}
Send-MailMessage @sMail