VMware Cloud Community
skasai_1
Contributor
Contributor
Jump to solution

Power CLI script to clone the virtual machine

HI,

Am having the error with following script to take clone for virtual machine

Could you please someone corrects the error

$VC='10.20.10.8'

$pwd = Get-Content C:\scripts\ap-vcs-credentials.txt | ConvertTo-SecureString

$credentials = New-Object System.Management.Automation.PsCredential “administrator@masscloudspace.local“, $pwd

Connect-VIServer -10.20.10.8 $VC

$vmName = 'MC-P-MailServer'

$cloneName = "$($)Varnikmail_Backup_$((Get-Date).ToString('MMddyyyy'))"

$oldCloneName = "$($)Varnikmail_Backup_$((Get-Date).AddDays(-2).ToString('MMddyyyy'))"

$ds = Get-Datastore | -Name 'Production_Backup'

$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}

Reply
0 Kudos
24 Replies
skasai_1
Contributor
Contributor
Jump to solution

Your suggestions very much help full...

Reply
0 Kudos
Richie55
Contributor
Contributor
Jump to solution

did you look in Local Security Policy/ Local Policies / Security options / Network Access : Do not allow storage of passwords and creds... set to disable.

Reply
0 Kudos
skasai_1
Contributor
Contributor
Jump to solution

HI Richie, Where i have to do this setup

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Run secpol.msc, then go to Local Policies.
But that setting might be set by a GPO, and then you need to talk with your domain admins.


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

Reply
0 Kudos
skasai_1
Contributor
Contributor
Jump to solution

Let me try this.

Reply
0 Kudos