Write-Host$PSVersionTableInstall-Module VMware.PowerCLI -Scope CurrentUserGet-Module VMware.PowerCLI -ListAvailableSet-PowerCLIConfiguration-InvalidCertificateAction IgnoreSet-PowerCLIConfiguration-Scope User -ParticipateInCEIP $false
Test Connectivity to ESXi Host
Connect-VIServer -Server 192.168.7.32
Get-VM
Or connect with domain user ($vcenter=”vcenter.paul.local”)
Show VM’s
To get vm Snapshot
# select vm$vm =Get-VM-Name DC1# Get snapshot name$snapshot =Get-Snapshot-VM $vm -Name “Base”# Get vmhost$vmhost =Get-VMHost-Name “192.168.7.32”# Get Data Store$ds =Get-Datastore-Name “datastore1-super20”# The name of the vm replaces {0}$linkedClone =“{0}.linked”-f $vm.name # To create new linked clone$linkedvm =New-VM-LinkedClone -Name $linkedClone -VM $vm -ReferenceSnapshot $snapshot -VMHost $vmhost -Datastore $ds# Create full independent version from linked clone$newvm =New-VM-Name “server.2019.gui.base”-VM $linkedvm -VMHost $vmhost -Datastore $ds# Create snapshot of new vm$newvm |New-Shapshot-Name “Base”# Removed old link$linkedvm |Remove-VM
#!/bin/sh#script to prepare ubuntu desktop vm for cloningapt-getupdateapt-getupgrade-y#open sshapt-getinstall-yopen-vm-toolsopenssh-servercat/dev/null>/var/log/wtmpcat/dev/null>/var/log/lastlogrm-rf/tmp/*rm-rf/var/tmp/*rm-f/etc/ssh/ssh_host*rm-f/etc/udev/rules.d/70-persistent-net.rulescat<<EOL|sudotee/etc/rc.local#!/bin/sh -etest -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-serverexit 0EOL# assumption is that the host is already named#echo ubuntu > /etc/hostnameapt-getcleanhistory-chistory-wchmod+x/etc/rc.localsystemctlstopapt-daily-upgrade.timersystemctldisableapt-daily-upgrade.timersystemctlstopapt-daily.timersystemctldisableapt-daily.timersudoaptautoremove-y#truncate the machine id to avoid duplicate dhcp# Changed lines belowecho-n>/etc/machine-idsudorm/var/lib/dbus/machine-idsudoln-s/etc/machine-id/var/lib/dbus/machine-idecho"remove git repo and then issue a shutdown - h now"
#################### cloneraux.ps1 ## Paul Gleason ##################### Check if connected to server$connectCheck = $global:defaultviserver |Select-Object Name -ExpandProperty Name# if not connected prompt to connectif ( $connectCheck -eq""){#Connect to vcenter $vcenterdomain =Read-Host"Please enter domain for vcenter"Connect-VISever-Server $vcenterdomain}# Show hostsWrite-Host"--VM Host--"Get-VMHost|Select-Object Name -ExpandProperty NameWrite-Host"-----------"$vmhostIP =Read-Host"Please enter VM Host IP you would like to use"# Show VMsWrite-Host"--VMs--"Get-VM|Select-Object Name -ExpandProperty NameWrite-Host"-------"$vmname =Read-Host"Please enter VM that you would like to clone"# Show VM SnapshotsWrite-Host"--Snapshots--"Get-Snapshot-VM $vmname |Select-Object Name -ExpandProperty NameWrite-Host"-------------"$snapshotName =Read-Host"Enter Snapshot that you would like to clone"# Show DatastoresWrite-Host"--Datastores--"Get-Datastore|Select-Object Name -ExpandProperty NameWrite-Host"--------------"$dsName =Read-Host"Select Datastore you would like to use"# Get Clone name$cloneName =Read-Host"Enter the name for the clone"# Get vmhost$vmhost =Get-VMHost-Name $vmhostIP# Get VM$vm =Get-VM-Name $vmname# Get snapshot name$snapshot =Get-Snapshot-VM $vm -Name $snapshotName# Get Data Store$ds =Get-Datastore-Name $dsName# The name of the vm replaces {0}$linkedClone = $cloneName# To create new linked clone$linkedvm =New-VM-LinkedClone -Name $linkedClone -VM $vm -ReferenceSnapshot $snapshot -VMHost $vmhost -Datastore $ds# Set Adapter$linkedvm |Get-NetworkAdapter|Set-NetworkAdapter-NetworkName 480-WAN