script clone
I'm looking for a way to automatically run a script to vCenter which would create a clone of each virtual computer. In addition, I would like to have it keep not more than 10 copies of each virtual computer.
Is this possible?
Thank you
Take a look at this script I wrote: ghettoVCB.sh - Free alternative for backup of VMS to ESX (i) 3.5, 4.x & 5.x and you can start the process of your vCenter server downtime using plink and paired SSH keys between hosts (i) ESX and vCenter system.
=========================================================================
William Lam
VMware vExpert 2009
Scripts for VMware ESX/ESXi and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
VMware Code Central - Scripts/code samples for developers and administrators
If you find this information useful, please give points to "correct" or "useful".
Tags: VMware
Similar Questions
-
Hi all
I am trying to automate the process of cloning for our databases BECAUSE a node, but I'm having a little trouble.
Here is the relevant part of my script (I think):
================================================================
Log = 'singleracclone.log' RMAN target sys / $PASSWORD @"(DESCRIPTION = (ADDRESS = (PROTOCOL = tcp) (HOST = $TARGET_HOST)(PORT=$TARGET_PORT)))"
(CONNECT_DATA =(SERVICE_NAME=$TARGET_SID))) "AUXILIARY sys / $PASSWORD @" (DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)
(HOST = $AUX_HOST) (PORT = AUX_PORT)) (CONNECT_DATA =(SERVICE_NAME=$AUX_SID) (UR = A))) "< < EOF
Run {}
allocate channels ch1 disc type;
allocate channel ch2 type disk;
allocate channel ch3 type disk;
allocate channel ch4 type disk;
allocate channel ch5 disc type;
allocate auxiliary channel ch6 type disk;
allocate auxiliary channel ch7 type disk;
allocate auxiliary channel ch8 type disk;
allocate auxiliary channels ch9 type disk;
allocate auxiliary channel ch10 type disk;
DUPLICATE TARGET DATABASE AT $AUX_DB_NAME
ACTIVE DATABASE
DB_FILE_NAME_CONVERT =)
"$TARGET_ASM_PATH", "$AUX_ASM_PATH".
);
}
=============================================================
Which gives the following error:
content of Script memory:
{
clone to stop immediately;
startup nomount clone;
}
execution of Script memory
Instance Oracle to close
output channel: ch1
output channel: ch2
output channel: ch3
output channel: ch4
output channel: ch5
RMAN-00571: ===========================================================
RMAN-00569: = ERROR MESSAGE STACK FOLLOWS =.
RMAN-00571: ===========================================================
RMAN-03002: failure of Db dual to the 16/07/2014 00:11:04
RMAN-06174: not connected to the auxiliary database
RMAN-03015: an error has occurred in the script stored memory Script
RMAN-04006: auxiliary database error: ORA-12514: TNS:listener is not currently of serv
ice requested in connect descriptor
=============================================================
As you can see I am using only the connection strings in my RMAN command to avoid fussing around with the tnsnames.ora.
As part of the script I launch a listener personalized running on a port prior arrangement with SID_LIST_LISTENER entry that points to the auxiliary database.
I can see the service when I do a LISTENER_CUSTOM lsnrctl status.
I can connect to the target and auxiliary on both servers by using connection strings. In fact my RMAN command above connect connection strings w / very well at the start. It's after the script memory has been run and stop the Oracle instance.
Any thoughts on what I'm missing?
Thanks in advance.
Kosh
> LISTENER_CUSTOM
does not match
> SID_LIST_LISTENER
The first entry indicates that the name of the listener is "LISTENER_CUSTOM". The second entry is trying to save the SID with a listener called 'LISTENER' and not 'LISTENER_CUSTOM' change the second entry at "SID_LIST_LISTENER_CUSTOM".
Hemant K Collette
-
How do the automatic deletion script clone virtual machines
Hello
We use the VM data recovery to clone virtual machines. We would like to clone some VMs on weekly basis but we need a script (or automatically) to remove the existing cloned VM automatically. VDR not clones a virtual computer when there is already a clone of this virtual machine.
The easiest way is to use the Windows Task Scheduler.
See runs a scheduled job PowerCLI Alan post.
-
Hello. First post, so please be nice. Running into errors of hella tried different methods to run this script:
$cloneparams = "c:\scripts\clone-parameters.csv".
$cloneparams import-csv - useculture | %{
Get-oscustomizationspec $_. "" customization ". Get-oscustomizationnicmapping | »
game-oscustomizationnicmapping - ipmode UseStaticIp - ipaddress $_.ip - subnetmask $_.subnetmask - passerelle_par_defaut $_.gateway
new-vm - vmhost $_. "' $vmhost '-name $_. "" vm_name "-location $_. "" folder "-model $_. "" resourcepool-$_ template_name. "" resource_pool "datastore-$_. "' datastore_name ' numcpu-$_. "" numcpu "memorymb-$_. "" memoryMB ' oscustomizationspec-$_ .customization - confirm: $false - runasync
}
The error looks like this:
New-VM: all parameters can be resolved by using the specified named parameters.
C:\scripts\clonescript.ps1:14 char: 7
+ new-vm < < < <-vmhost $_. "' $vmhost '-name $_. "" nameyname "-location $_. "" folder "-model $_. "" resourcepool-$_ template_name. "" resource_pool "datastore-$_. "' datastore_name ' numcpu-$_. "" numcpu "memorymb-$_. "" memoryMB ' oscustomizationspec-$_ .customization - confirm: $false - runasync
+ CategoryInfo: InvalidArgument: (:)) [new-VM], ParameterBindingException)
+ FullyQualifiedErrorId: AmbiguousParameterSet, VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
The .csv has these column headings (with the appropriate values to each for a bunch of new virtual machines to create):
vm_name template_name datastore_name customization VLAN intellectual property entry door subnet mask DNS folder resource_pool numcpu memoryMB vmhost The oscustomizationspec bit seems to work, but the New - VM cmdlet is obviously not happy.
I noticed others have posted similar code that seems to work for them. All thoughts were highly appreciated.
Thank you!
You have about the New - VM cmdlet parameters that are unique to different parametersets. You cannot combine unique parameters of different parametersets.
I f you look at the New - VM cmdlet, you will notice that there are 4 available parametersets.
In your case, by selecting the parameter of the model, you fall in the 2nd set.
In the red rectangle, you see the other settings, you can select.
In your case, the parameters ResourcePool, NumCpu and MemoryMB cause the conflict.
If you want to change the distribution of CPU and memory of the model, you will need to do after the virtual machine has been created with the Set-VM cmdlet.
Similarly, you can use the Move-VM to change the ResourcePool, after the virtual machine has been created.
Pretty sweet?
-
Hello
I am facing clone after error on aix 5.3 OS 11i when I run the script clone post about db, he error.share any solution is much appreciated
$ perl adcfgclone.pl dbTier
Enter the password [APPS] APPS:
First create a new context for the cloned system file.
The program will ask you for information on the new system:
RC-50004: an error occurred in CloneContext:
null
Check the log file CloneContext_01210431.log for more details.
ERROR: creation of context not completed successfully.
Please check for errors in the /tmp/adcfgclone.err file
Thank you
MAAN
Published by: user1116442 on January 20, 2011 03:40Please see the two docs referenced above.
Thank you
Hussein -
Clone of Oracle11g database problem
Hello
I installed Oracle database 11g on Windows. Now, I want to clone the same to another location on the same system. Here are the details:
ORACLE_HOME: E:\Sujatha\Oracle11g\Oracle_home
ORACLE_BASE: E:\Sujatha\Oracle11g
Cloned details:
I copied the oracle above home to another location, as below:
ORACLE_HOME: E:\Sujatha\Oracle11gclone\Oracle_home
ORACLE_BASE: E:\Sujatha\Oracle11gclone
I'm following the instructions of http://download.oracle.com/docs/cd/B28359_01/em.111/b31207/oui6_cloning.htm#CEGCIEJD
so I went in the following at the command prompt.
E:\Sujatha\Oracle11gclone\Oracle_home\perl\5.8.3\bin\MSWin32-x86-multi-thread > pe
RL E:\Sujatha\Oracle11gclone\Oracle_home\clone\bin\clone.pl ORACLE_BASE = E:\Sujat
ha\Oracle11gclone ORACLE_HOME = E:\Sujatha\Oracle11gclone\Oracle_home OraDb11g_hom
E2
Following is the error I got:
ERROR: Invalid host name specified. Abort the clone operation.
NAME
Clone.pl - Clones a DB Oracle 10 g Release2 Oracle home. This script clone
the software only. He doesn't clone the database running instances in this House
.
Please notify.
Thank you sincerely,
SKHello
Yes try with the new name as OraDb11g_Clone_Home.
Hope it should work.
Kind regards
Xaheer -
Hello
does anyone know how to automate pre scripts clones DB and Apps Tier that is
Perl adpreclone.pl dbTier
Perl adpreclone.pl appsTier
Each of them asking the password scheme apps as an input parameter. I want to be able to pass this parameter automatically, so I can run these jobs via cron on a daily basis until I backup my Apps and RDBMS software stacks.
any help appreciated,
Jim
Hi Jim,.
When the preclone running on the db layer will prompt you for a password and the apps does not require a password.
Run the preclone on two levels, just to have the following code before your backup of the script part, following is a coded coding:
CD/u01/visys/inst/apps/VIS_vision/admin/scripts
Perl adpreclone.pl appsTier
CD /u01/visys/db/tech_st/11.2.0/appsutil/scripts/VIS_vision
Perl adpreclone.pl dbTier pwd = apps
Note: Make sure that you change the path according to your environment.
Thank you &
Best regards
-
need help with correction QVC to duplication on regular basis
Hello
I use Oracle 10.2.0.4 on Win 2008 R2. We have Archive mode and no catalog rman is used. I have a requirement where I have to reproduce prod weaned on a regular basis to the development server.
I created the batch a few files so that the entire process automatically. Stored all the scripts in Directory of c:\script\clone\. +.
I took the backup copy of the password and spfile Server prod and copied on the development at the same server.
Here are the scripts that I have performed in the order:
* 1_clone.bat*
Set ORACLE_SID = orcl
sqlplus / as sysdba @c:\script\clone\2_test.bat
* 2_test.bat*
immediate stop
startup nomount
rman target sys/oracle@live nocatalog auxiliary host / @c:\script\clone\3_rman.rcv
* 3_rman. RRS *.
Run {}
allot of drive type d1 track auxiliary;
double-target database ORCL NOFILENAMECHECK;
}
output
When the duplication process in about in the end, I get error below:
content of script memory:
{
clone of judgment;
startup nomount clone;
}
execution of Script memory
RMAN-03002: failure of dual DB at 31/07/2012 08:02:21
RMAN-03015: an error has occurred in the memory stored script script
RMAN-06136: the auxiliary database Oracle error: ORA-01013: user has requested the cancellation of the current operation
Complete recovery manager
SQL >
When I press exit, this window closes and I can run the alter database open resetlogs; -command with a new sql command prompt. I check online and some suggest that there could be a window with system user. Please suggest changes in the script.
Best regardsHello;
Have another session with the user of the system will cause rman raise this error. For example another session is used to start the database in nomount is always active mode.
During the cloning process the rman session must be exclusively connected to the instance auxiliary (no other sessions are allowed).
Double post
request for assistance with rman cloning script
Best regards
mseberg
Published by: mseberg on July 31, 2012 05:02
-
The top INST may be transferred for cloning when the system is in place.
Hi all
I had to make a clone of the system E-Business suite R12. I shut down the system and subsequently wanted to break into sections backups and transfer them to target systems by breaking down to sub sets (I had to coz I had a problem of space).
Anyway, I was able to consistently TOP and TOP DB APPS backup, but INST HIGH has not had saved... I ran the scripts before clones before this backup has been performed, but could someone confirm if I can take backup of the SUPERIOR INST part while the system is in place coz I have to finish the cloning as soon as POSSIBLE.
Rgds,
AsifThank you very much, but I need an explicit answer as confirmation since I just started my job as APPS DBA and still to learn...
It's OK :)
Sorry to requestion on the same. On the other hand and finally could you also say with custody, if TOP INST will be automatically created after running the script clone post.
Correct, it will be created after you run the postclone script.
Thank you
Hussein -
find the right backup of cloning using up the time option
Hello
I'm trying to create a script to find out what files to backup (backup rman, rman backup control file and archivelogs) are needed to create a clone of production data base lets say for 1 month ago or two weeks ago.
My backups are marked, performed on the disk, but a night job takes the disk backup files and moves them to tape.
So, before I can restore correct correct tape files, I need to know what files to backup should I restore a band.
I could start the clone and she'll tell me it cannot find the files of backup that is named xxx, yyy and it will eventually error and output, but I find the files.
The idea is to find the files before the script (script clone) could not find the right files.
I tried to use the v$ element_sauvegarde, v$ backup_files equivalent rc_ view (s) and tried to join them, but I couldn't find the join columns. I tried stamp column. This gives me some information so I can find the files, but I need to know the approximate duration of the backup.
So my question is: how RMAN queries it sees? (v$ backup %) I couldn't find a link to foreign key between tables.
Here is the result of what I managed to find, but I have to give the approximation of 1 hour (1 hour before NMR files have been generated and 1 h after) so I could find the controlfile files and the archivelogs rman backup files.
'BACKUP' 'BS_TYPE' 'PKEY' 'STAMP' 'RMNFILE' 'STATUS' 'TAG.
"BACKUP SET" "ARCHIVED LOG" 2568 751143608 ' / bckploc/514_2576.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "ARCHIVED LOG" 2566 751143608 ' / bckploc/514_2575.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "ARCHIVED LOG" 2567 751143607 ' / bckploc/514_2574.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "ARCHIVED LOG" 2569 751143607 ' / bckploc/514_2573.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "ARCHIVED LOG" 2570 751143633 ' / bckploc/514_2577.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "DATA file" 2571 751143635 ' / bckploc/514_2581.rmn "'AVAILABLE'"DB_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "DATA file" 2572 751143635 ' / bckploc/514_2580.rmn "'AVAILABLE'"DB_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "DATA file" 2573 751143635 ' / bckploc/514_2579.rmn "'AVAILABLE'"DB_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "DATA file" 2574 751143635 ' / bckploc/514_2578.rmn "'AVAILABLE'"DB_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "ARCHIVED LOG" 2575 751143711 ' / bckploc/514_2582.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
"BACKUP SET" "DATA file" 2576 751143715 ' / bckploc/c-3567074004-20110514-00 '"AVAILABLE" ' TAG20110514T190155' ".
Any suggestions are appreciated.
Thank you
DanielHello
I tried to use the v$ element_sauvegarde, v$ backup_files equivalent rc_ view (s) and tried to join them, but I couldn't find the join columns. I tried stamp column. This gives me some information so I can find the files, but I need to know the approximate duration of the backup.
So my question is: how RMAN queries it sees? (v$ backup %) I couldn't find a link to foreign key between tables.If your question is only to reach the point of view.
Then a tip: you should always join columns (STAMP and COUNTY)for example
bs_stamp bs_count SET_STAMP SET_COUNT
SELECT BP.RECID, BP.STAMP, BP.RECID, BS.RECID, BP.SET_STAMP, BP.SET_COUNT, PIECE#, COPY#, STATUS, BP.COMPLETION_TIME, HANDLE, BS.CONTROLFILE_INCLUDED, BS.BACKUP_TYPE, TAG, DEVICE_TYPE, MEDIA, BYTES, COMPRESSED FROM V$BACKUP_PIECE BP, V$BACKUP_SET BS WHERE HANDLE IS NOT NULL AND BS.SET_STAMP = BP.SET_STAMP AND BS.SET_COUNT = BP.SET_COUNT; SET_STAMP SET_COUNT COMPLETION_TIME HANDLE CONTROLFILE_INCLUDED TAG --------- ------ ------------------------- --------------------------------------------------------------------------------- -------------------- ------------------- 751030325 109 13/05/11 +FRA/db10g/backupset/2011_05_13/annnf0_backup_full_0.379.751030327 NO BACKUP_FULL SELECT FILE_TYPE, FILE_TYPE, STATUS, F_NAME FROM V$BACKUP_FILES WHERE BS_STAMP = 751030325 AND BS_COUNT= 109; FILE_TYPE STATUS FNAME -------------------------------- ---------------- ------------------------------------------------------------------ ARCHIVED LOG ARCHIVED LOG ARCHIVED LOG ARCHIVED LOG PIECE AVAILABLE +FRA/db10g/backupset/2011_05_13/annnf0_backup_full_0.379.751030327
In this example, I have 4 archivelogs in the backuppiece.
I hope this can help you
See you soon,.
Levi Pereira -
A seemingly silly question, but I'll ask anyway.
I cloned our 11.5.10.2 to a Dev system Production System and I need to update the DB with the latest applications etc.. Of course I can replace all the DB files and have the most recent copy, but won't I lose all of my changes and settings that stores the Apps in the DB?
Can I move the db files and rerun the script clone and don't forget not all the settings I changed, or are the settings Ko, iSupport and apps all stored in particular the tables that I can jump bringing more?
Thank you in advance.Terry,
but won't I lose all of my changes and settings that stores the Apps in the DB?
No, unless you have applied the fixes on the application tier node (source instance) since the last time you cloned the target instance. Or, you added new files (forms/reports/images... etc).
Can I move the db files and rerun the script clone and don't forget not all the settings I changed, or are the settings Ko, iSupport and apps all stored in particular the tables that I can jump bringing more?
The steps are covered in the quick Clone docs (see section "Refreshing a target system").
Cloning Oracle Applications Release 11i with rapid Clone [ID 230672.1]
Cloning Oracle Applications V12 with rapid Clone [ID 406982.1]Thank you
Hussein -
Hi all,.
I would kindly ask your help with a script that needs to run as a scheduled task. It is functional, but does not correct and little need for love at the end...
I want to create a script that
- find a virtual machine with a pattern on its behalf (realized and works)
- delete a virtual machine with a reason given in his name (completed works)
- create a clone of a virtual machine (completed works)
- move that created clone (upstairs) and move it to a folder named (open)
or the fact in the clone process
I realized thus far:
Add-pssnapin VMware.VimAutomation.Core
# Import CSV backup
$backupinfo = import-Csv C:\scripts\vm_backup\test.csv
VCenter servername #Set
$vcenter_server = "name servers".
#Connect to vCenter
SE connect-VIServer $vcenter_Server# BEGIN OLD BACKUP CLEANUP
#Select all old backups
$old_backups = get - VM *-backups
{if ($old_backups)}
{foreach ($backup_vm to $old_backups)
Get - VM $backup_vm | Remove-VM - DeleteFromDisk-confirm: $false
}
}# START QUEUING NEW CLONES
#Increment through CSV
{foreach ($customer to $backupinfo)
$target_host is get-VMHost-name $customer. TargetHost
If {($target_host)
Date format #Set for clone names
$date = get-Date-Format 'YYYY-MM-dd ".
Date format #Set for emails
$time = (get-Date - f "Hh: mm")
#Get SourceVM
$vm is get - VM $customer. SourceVM
# Create new snapshot clone
$cloneSnap = $vm | New-Snapshot - name "instant Clone.
# Get the managed object display
$vmView = $vm | Get-View
# Get the managed folder object reference
$cloneFolder = $vmView.parent
# Construction specification clone
$cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec
# Make linked disc specification?
$cloneSpec.Snapshot = $vmView.Snapshot.CurrentSnapshot
#Set VirtualMachineRelocateSpec
$cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec
#Thin commissioning
$cloneSpec.Location.Transform = [Vmware.Vim.VirtualMachineRelocateTransformation]: sparse
#Target data store
$cloneSpec.Location.Datastore = (get-Datastore-name $customer. TargetDS | Get - View). MoRef
#Target host
$cloneSpec.Location.Host = (get-VMHost-name $customer. TargetHost | Get - View). MoRef
#Target list of resources, from the first VM in the TargetHost
$cloneSpec.Location.Pool = (get-VMHost-name $customer. TargetHost | Get - VM | Select-Object - 1 first | Get - View). ResourcePool
Name of clone #Set
$cloneName = ' date of $vm-$- $temps - backup ".
# Create clone
$clone_task = $vmView.CloneVM_Task ($cloneFolder, $cloneName, $cloneSpec)
# Remove snapshot created for clone, will automatically queues
Get-Snapshot - VM (VM-Get-name $customer. SourceVM) - name $cloneSnap | Remove-Snapshot - confirm: $False
}
}# Move folder in VM Clone
Move-VM - VM * - backups - Destination CloneVCentre #Disconnect
Disconnect-VIServer-confirm: $falseThe script itself runs so far and does what it should, but the scheduled task is always "in process of execution". Now, I created a work around in this way, I have finished the task after two hours of running; but there must be a better solution that works properly.
As well as the part with the rise of the virtual machine.Could you maybe help me or have a good idea how to solve this problem?
Thanks in advance
Try again with
PowerShell-no interactive - noprofile - executionpolicy override - file C:\scripts\scriptname.ps1
-
Can someone provide me with a Powercli script to clone a vm under tension of mass and customize them.
And where is the script will fetch this information?
-
I seek to create a PowerCLI script to clone a virtual machine and to overwrite any existing clones that are present. Just do some research, here is what I found:
VM2 - VM VM1 - Datastore datastorename - vmhost hostname new-VM-name
I have not yet tested the script, but it looks like it will at least part of what I seek to accomplish. Do I need to use the Datastore and VMhost parameters? And I can do to remove any clones existing before running the script? Thank you.
You need the VMHost parameter, or a ResourcePool or a paralytic.
You need not to the data store setting, if the new virtual machine can be created on the same data as the source of VM store.
If you want to override this behavior and use another data store, you must use the data store setting.
You can do a Get - VM on VM2 name and if there is remove it.
Something like that
$newVMName = "VM1"$sourceVMName = "VM2"$esxName = "MyEsx" Get-VM -Name $newVMName | Remove-VM -DeletePermanently -Confirm:$falseNew-VM -Name $newVMName -VM $sourceVMName -VMHost $esxName
-
Script to wait for Clone task is completed
Good day, as part of the post, I run a command that enables the NIC and sets the right Port-Group of cloning process. I put a sleep command in each environment is diferrent, so I find myself always change this duration of sleep because the cloning process does not end in the time of sleep and the rest of the script fails. So in order to get rid of the sleep control that I want to capture the CloneVM_Task and pass this parameter to wait-task that will force the completion of the ClonVM_Task. I could just make sure no other tasks are running but this task, but as we all know that alays can't be the case. So that's what I did.
I begin a deployment of FVO to have an another long running task. Then I run the script.
If ((Get - PSSnapin - name Vmware.VimAutomation.Core - ErrorAction SilentlyContinue) - eq $null) {Add-PSSnapin "Vmware.VimAutomation.Core"}
# Virtual Center details
$server_address = "MYvCenter name" or IPSE connect-VIServer-Server $server_Address - user username-pass password - WarningAction SilentlyContinue
#Create Master VM Templates
#
# Here we import the CSV file with the account information and he piped in a Foreach-object
# Creating a Variable that imports the csv file that contains all data of the virtual machineCD "e:\Scripts.
$InputFile = import-Csv "E:\scripts\mycloneinput.csv".
$InputFile | {ForEach-Object$ip = $_. VM_IPAddress
$GName = $_. VM_Guestname
$TName = $_. Template_name
$HName = get-VMHost "myhostname" # 1 first Select
$Desc = $_. Description
$Dstore = $_. Datastore_Name
$Spec = $_. Customization
$Folder = $_. Folder
$Sfolder = $_. Subfolder
$NIC = $_. NIC
$NIC_Lable = $_. NIC_Label
$Gateway = $_. NIC_Gateway
$SubnetMask = "255.255.255.0".
$DNS1 = $_. DNS1
$DNS2 = $_. DNS2
Write-host "creation: ' $GName
Write-host "template name is: ' $TName# This takes variables and creates the virtual machine
Get-OSCustomizationSpec $Spec | Get-OSCustomizationNicMapping | »
Game-OSCustomizationNicMapping - IpMode UseStaticIP - $ip - $SubnetMask subnet mask - DNS IpAddress $DNS1, $DNS2 - DefaultGateway $Gateway
New-VM-name $GName - location $Folder - model $TName - host $HName - $Dstore - $Desc Description data store - OSCustomizationSpec $Spec - RunAsync-confirm: $false
#######################################
#Waiting for cloning process to finish.
#######################################$$$ Under notes show a little history of how I got to this point.
$$ Note1: the first attempt, I just captured running tasks and their past to the task pending. "Well, since the deploy OVF and ClonVM_Task where it runs would wait up to two when completed by the end."
$$ Note2: so I added the If Else loop below that failed, because $RTask never equaled only CloneVM_Task, but was a table of two.
$$ Note3: I tried to us below to separate the two tasks to help
# $RTask = get-task-status running (who captured the two tasks running)
# $Array = $Rtask.Split("") (Errored with the method call failed because [System.Object []] contains a method named 'Split'.)
# So I tried to divide the table like this. ForEach ($Task in $Rtask.Name - Split("")) {Write-Host "my tasks are:" $Task}
Get-task-status Running | Export-CSV "E:\scripts\Current_Tasks.csv".
$InputFile2 = import-CSV "E:\scripts\mmca\mmca_Current_Tasks.csv".
$InputFile2 | {ForEach-Object
$RTask = $_. Name
Write-Host "current task is: ' $RTask
IF ($RTask - eq "CloneVM_Task") {}
Write-Host "current task of Clonning is: ' $RTask
Write-Host "in the meantime the cloning process finish.
Waiting-task-task $MyTask
}
Else {}
Write-Host "no cloning process is executed.
}
}
# This allows the NIC and set the correct Port Group
Get-VM-name $GName | Get-NetworkAdapter-name $NIC | Together-NetworkAdapter - NetworkName $NIC_Lable-confirm: $false - StartConnected $true
}When I run the present, I get the following:
# #This shows the task start Clonning #.
erverId: /[email protected]:443 /
Status: running
IsCancelable: true
PercentComplete: 5
StartTime: 03/05/2013 00:52:13
FinishTime:
ObjectId: VirtualMachine-vm-382
Result:
Description: Clone virtual machine
ExtensionData: VMware.Vim.Task
ID: Work-task-2070
Name: CloneVM_Task
UID: /[email protected]:443 / task = work-work-2070 /#########################################################
# #Runs through the tasks running.
Current task: deploy the model to the FVO
No cloning process is executed# Ignore deploy it task #.
# #Matches the If statement and continues to process #.
Current task is: CloneVM_Task
Task current Clonning is: CloneVM_Task
Wait for the cloning process to complete# #Error #.
Waiting-Task: cannot bind parameter 'task '. Impossible to convert the value of 'CloneVM_Task' to type 'System.String' type 'VMware.VimAutomation.Sdk.Types.V1.Task '.
E:\scripts\Working_Create_Master_Templates.ps1:71 tank: 24
+ Wait-task-task < < < < $RTask
+ CategoryInfo: InvalidArgument: (:)) [waiting-Task], ParameterBindingException)
+ FullyQualifiedErrorId: CannotConvertArgumentNoMessage, VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTask$$$ Under notes show a little history of how I got to this point.
Note1: The first attempt, I have just captured tasks currently running and pending their past to the task. "Well, since the deploy OVF and ClonVM_Task where it runs would wait up to two when completed by the end."
NOTE2: So I added the If Else loop below which failed because $RTask never equaled only CloneVM_Task, but was a picture of two tasks.
Note3: I tried to use the following to divide the two tasks:
$RTask = get-task-status running (who captured the two tasks running)
foreach ($Task in $Rtask - Split(""))
{
{Write-Host "my tasks are:" $Task}
IF ($Task - eq "CloneVM_Task") {}
Write-Host "current task of Clonning is: ' $Task
Write-Host "in the meantime the cloning process finish.
Waiting-task-task $Task
}
Else {}
Write-Host "no cloning process is executed.
}
}# #Output the little script above #.
Current task: deploy OVF model CloneVM_Task
My tasks are: deploy
My tasks are: OVF
My tasks are: model
My tasks are: CloneVM_Task
Task current Clonning is: CloneVM_Task
Wait for the cloning process to complete
Waiting-Task: cannot bind parameter 'task '. Impossible to convert the value of 'CloneVM_Task' to type 'System.String' type 'VMware.VimAutomation.Sdk.Types.V1.Task '.
Online: 11 char: 24
+ Wait-task-task < < < < $Task
+ CategoryInfo: InvalidArgument: (:)) [waiting-Task], ParameterBindingException)
+ FullyQualifiedErrorId: CannotConvertArgumentNoMessage, VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTaskI'm new to Powercli and I've scoured Google for a possible answer. I thought I might have a solution that has been published on the VMware PowerCLI Forum, but I couldn't get this to work. Any help would be greatly appreciated.
#########################################
I wasn't worried about how to tasks where splits, unless I was trying to follow the import fo the OVF, so that the script went into the loop If and as one of the names for CloneVM_Task then he Treaty. But I got the same error I did in the last version of the above script. That's why I have the version curent thinking that if I exported and then imported the tasks it might make a difference.
I'm new to Powercli and would like a little help. I am either very close or by a mile off. :-)
Thank you
Mitch
Why don't you store the the task object that is returned when you use the RunAsync switch?
You can create a loop around the State and wait until the clone job is done.
$task = New-VM -Name MyVM ... -RunAsync while($task.ExtensionData.Info.State -eq "running"){ sleep 1 $task.ExtensionData.UpdateViewData('Info.State') }
The big difference with the Wait-job cmdlet, it is that this will allow you to perform additional work in the While loop.
Waiting-task the cmdlet waits just until the task is finisned and you can not do anything else.
Maybe you are looking for
-
email from Apple asking to restore my ID...
Is - this legitimate or someone just phishing?
-
How to get back to normal. F11 does not work. Don't have the bar menus or dock.
I went to the display of full backups. Now, I can't go back to the normal screen size. I don't have tools, menu bar or dock. Cannot click on anything. F11 is not working with Mac Snow Leopard.
-
I have laptop HD and and tv UHD contented to the PC. ITunes STINKS about this. I will not buy any more movies to apple because of this. They really need to act together. They suck at it.
-
Random popping / ticking during audio playback
Hey,. W500 4058-CTO running x 64 Vista Ult using drivers latest 5th Jan. I feel random noises clicking / popping during audio playback MP3 of WMP11 on speakers/headphones. If I use my headset Bluetooth AD2P no questions, yes mp3 and WMP is fine. Some
-
Hello I recently upgraded my IBM ThinkPad T40 of Windows 2000 Pro for Windows XP Professional (Service Pack 2). Clean install. I couldn't connect wirelessly to the Internet after the installation. I looked in Device Manager and saw yellow? against th