New folder and waiting-task

Hello

I am new to VI Toolkit (and indeed to Powershell) but I have a part of a script that I'm building which I'm totally stuck on the syntax for:

The script is as follows - he tries to create a temporary folder for virtual machine, run a clone of a guest in the new folder (and especially a new store of data one is on), then remove the prompt (without 'deletefromdisk' for the new data store has a backup of the files), then deletes the temporary file of virtual machine.

$sourceHost = "xxx.xxx.xxx.xxx" # this is a VC, not an ESX Server.

$vm2c = "yyyyyyyyyy".

$dataCenter = "zzzzzz".

$destcln = $vm2c + "-clone".

$destdatastr = "Adrar".

$foldername = "~ bath.

$sourceVIServer = connect-VIServer-Server "$sourceHost".

Get-file 'vm ' | New-folder - name $foldername

$FolderID = get-file-name $foldername

$targetfolder = get-view ($FolderID) USER.USER

$destdsview = get-view (get-datastore-name $destdatastr) user.user

$VMCloneSpec = new-Object VMware.Vim.VirtualMachineCloneSpec

$VMCloneSpec.Location = new-Object VMware.Vim.VirtualMachineRelocateSpec

$vmclonespec.location.datastore = $destdsview.moref

$VMCloneSpec.powerOn = $false

$vmclonespec.template = $false

$clntask = (get-View (Get-VM-name $vm2c) USER.USER). CloneVM_Task($targetfolder.) MoRef, $destcln, $VMCloneSpec)

Wait-job $clntask.value

Remove-VM (VM-Get-name $destcln)

Remove-file-name $foldername

The first question I have is with New-folder.    I discovered to create a folder that can contain guests, you need to do under the "vm" folder   In a vCenter, however I have three individual data centers, it creates the folder under ALL data centers and the script barfs as the search for the file using get-file fails (as there are 3).   Is there a way I can specify a specific data center to add my file?

The second question I have is Wait-task.   The piece of code that I use comes from these forums and running a CloneVM_Task.   I'd give my script to wait for this task to be completed (because of course, I want to follow forward with a deletion-VM on the new virtual machine "cloned").   I can't wait using any combination of ' wait-job-$clntask.value the task ","wait-task-task $clntask', "wait-task $clntask" or "task waiting $clntask.value»   Does anyone have the correct syntax for what I'm trying to do - is still possible?

Thanks in advance...

You can use a Get-Data Center, Get-file (or a sequence of these) to move to the location where you want to create the new folder.

Suppose you have 2 data centers DC1 and DC2, each with a folder called Templates.

If you want to create a subfolder in DC2 under the Templates folder you could do it like this

Get-Datacenter DC2 | Get-Folder Templates | New-Folder NewFolder

The Wait-job cmdlet works with an TaskImpl object.

The CloneVM_Task method returns an object task .

See also -vm, new new hard drive, wait-job

To wait for the completion of the task, you can use a construct like this

$taskMoRef = (Get-View (Get-VM -Name $vm2c).ID).CloneVM_Task($targetfolder.MoRef, $destcln, $VMCloneSpec)

$task = Get-View $taskMoRef
while ($task.Info.State -eq "running" -or $task.Info.State -eq "queued") {
  sleep 2
  $task = Get-View $taskMoRef
}

Tags: VMware

Similar Questions

  • Copy a single file to the new folder and remain in multiple versions

    Hello. I am looking for assistance in the next issue. I have a script that helps me to look for a file name and rename it and I have a script that looks like a file and moves it to a new folder. I need one that will combine the two aspects in one based on the example as follows:

    I have a picture but need to rename the same file in several versions. (i.e. original image name 7HABLH.jpg to be copied to a new location and renamed with several different names 6HABLH_01.jpg, 6HABLH_02.jpg, 6HABLH_03.jpg, etc...). This produces even a lot of pictures and are all contained in a CSV file that is configured as below

    My end result would be the image in the folder/column 'OldImageName' is copied into a new folder and renamed the folder/column "NewImageName." Hope my request is logical that I am a poster the first time also trying to learn the script but I don't have a lot of time to achieve and could use as much help as possible.

    Hope that someone out there may be able to help.

    Windows or OS X?

    TT2

  • I can't rename a new folder, when I create a new folder and then rename the folder, the folder was renamed "new folder."

    original title: renaming a folder

    Hello, I have a problem with windows vista, I can't rename a new folder, when I create a new folder and then rename the folder, the folder was renamed "new folder" can you help me? to solve this problem?

    Hello, I have a problem with windows vista, I can't rename a new folder, when I create a new folder and then rename the folder, the folder was renamed "new folder" can you help me? to solve this problem?

    Only time that happens, in my limited, knowledge is... If you use a 'illegal' name, such as ":" symbol. There are symbols, that you cannot use as part of a name. When this happens, you should get a warning indicating that the name is not allowed, something to that effect. Then he returns itself back to the new folder.
    Suggest you try again with conventional names. See if it works or not.

    t-4-2

  • Moving files: I am wanting to put the existing files to a new folder, how do I create a new folder and move those file to the new folder?

    I am wanting to put the existing files to a new folder, how do I create a new folder and move those file to the new folder?

    I am wanting to put the existing files to a new folder, how do I create a new folder and move those file to the new folder?

    Hello

    Go t the location where you want to create the new folder, right-click and select new/folder. Name the folder.

    Go to where the files, select the files and then use the right mouse button to drag the files into the new folder. When you drop the file, a pop-up menu, select the Move option.

    Let us know if you have any other questions.

    Thank you for using Windows 7

    Ronnie Vernon MVP
  • What happened to my ability to create a new folder and how do I solve this problem?

    I can no longer create a new folder on my PC. I used for the right click, select 'new', choose 'new folder' and it appeared.  Now, "new folder" is not in the list, and I can't create a same folder by selecting the option from the top of an existing folder. Anyone know what happened?  Thank you!

    I don't know why, but what is happening lately for a lot of Win7 users.
     
     

    How to remove and restore the default context Menu items 'New' in Windows 7 and Windows 8
    http://www.SevenForums.com/tutorials/28677-new-context-menu-remove-restore-default-menu-items.html

    If still no joy, see the 'response' by Linda Yan in this thread.
    http://social.technet.Microsoft.com/forums/en-us/w7itprogeneral/thread/97de8a2a-12f2-4381-A409-a78f4ae551cf/#99395761-56de-4a76-8C2A-eab498ad735a

    Tip: When you save the text in Notepad, the default file format is .txt. Replace all files.

  • How can I create a new folder and add some choose another folder

    How can I create a new folder and add some pictures a different folder?

    Click Start-> computer.  Navigate to where you want to create the new folder.  Then, hold down the ALT key and press F.  Point again-> file and click folder.  Now, you have created the folder if you need to name it.  Type the name you want to give the file and press ENTER.  Now you have the new folder with the name you gave it.  Use him copy / paste to copy the images to the new folder.

    Good luck.

  • I just renew my creative cloud with a new card and waited 15 minutes and it still says that I have to renew it... Please help

    I just renew my creative cloud with a new card and waited 15 minutes and it still says that I have to renew it... Please help

    Please you bought online to your Adobe.com account.

    Concerning

    Stéphane

  • When I copied the images in a new folder and want to see them they do not appear in this order!

    I save all my pictures in Windows Photo Gallery. I create a new folder on the desktop for example and copy photos, then I klick to the first image to start the search, click on the arrow to view the next photo, but they come in mixed order and not in the same order, I copied the. I tried to rename the when they are copied, but who can help doesn´t. What's wrong?

    I save all my pictures in Windows Photo Gallery. I create a new folder on the desktop for example and copy photos, then I klick to the first image to start the search, click on the arrow to view the next photo, but they come in mixed order and not in the same order, I copied the. I tried to rename the when they are copied, but who can help doesn´t. What's wrong?

    ===============================================
    Photos will be AutoSort first alphabetically then digitally.

    To maintain a certain order during the copy in a new folder or
    for a CD... try renaming the files when they are in the order
    you prefer as follows:

    Organize files the way you want and go to... Edition / select all.

    Right-click the photo 'first' the selected (highlighted)
    Group and from the menu choose... Name change.

    For the first name... Enter a descriptive word for the group,
    a space, and the first number

    Summer vacation (10001) .jpg

    (Yes... Use parentheses and start the number with a 1)
    (If you want to add a descriptive title to batch... Leave a
    space after the last letter and before the first parenthesis)

    Press on... Enter and Windows renames the remaining photos...

    Summer vacation (10002) .jpg
    Summer vacation (10003) .jpg
    Summer vacation (10004) .jpg

    Good luck...

  • QUERY ON THE NEW FOLDER AND BACKUP/RESTORE

    I renamed a NewFolder of office and introduced the library... documents

    departure: documents show then somewhere else... EXPECTED

    However even though I have new files to this place that they do not appear on the backup.

    I tried to prove what is on the DVD of backup (backup of windows!)

    (to prove my backups are ok I crash hard drive!)

    I did something wrong re new folder?

    Thank you very much

    Windows 7

    Hello Shawn

    Thank you. After three years! Find out who is responsible for what and why.

    I have dell support phone (I live in the United Kingdom) with free telephone support.

    Ideally would like it to email or chat with dell on free number not BT 0844 expensive number

    Not your problem! Would like that explained by dell at the time I bought the laptop. Very few documents when my computer arrived very quickly in China.

    Thanks again

    I managed to prove once last night the backups missed me was on the DVD RW.  Only once!

    Walter

  • I can't create a new folder. I don't know why. I click on new folder and nothing happens not either new folder appears in the menu when I right click. Someone knows how to fix this?

    For some reason, I am unable to create a new folder on one of my readers. When I click on new folder, nothing happens and if I right click in a box empty when the menu appears, new folder, I don't have the option of the new folder. I have no idea how to solve this problem. Does anyone have any suggestions. Thank you.

    What happened a bit in the past, but we see a lot more often recently.
     

    How to remove and restore the default context Menu items 'New' in Windows 7 and Windows 8
    http://www.SevenForums.com/tutorials/28677-new-context-menu-remove-restore-default-menu-items.html
     
     

    Tip: When you save the text in Notepad, the default file format is .txt. Replace all files.
     

     
  • LR 5.7 - impossible to create a new folder and import photos in this folder [was: could Adobe Lightroom Fix so that it is functional?]

    I can't believe that after use adobe for years that lightroom can be this difficult to maneuver - please fix this intuitive user program. It is so far for simplicity of use. Please fix or return to support the opening. My images/files and folders are a total disaster.

    .. .you you create a folder and cannot import directly in this folder, etc.

    Perhaps the difficulty here, comes to design two sequential tasks, rather than one integrated task, for example:

    • Make a folder, manually put the pictures in there, then go and find this place AGAIN, for an import with TDA
    • Create a folder, and then to go and find this place again as an import with the copy destination

    No one who is attractive to me. Lightroom is IMO more useful when rationalizing away the boring stuff.

    LR can make the file for YOU and drop the images into that, according to your instructions, while import.

    "Let's say that my system was focused on the year at the top level, then the month, then records a day in this framework, each preceded the date in a format standard, so-called ' 2016 - 07 - 16. LR can run it for me immediately, as an automatic process of hands-free and without error. So if I want to, after import, I can add a descriptive text (customer, situation, whatever) on a given from LR folder name.

    Otherwise I want can I have LR just go a standard parent folder and then type a name of subfolder custom in the dialog import (Destination Board) in order to meet the specific needs of this - if not automated - import with a copy. Type in certain keywords lot too, perhaps.

    IOW: remember that an import preset to re - initialize the import settings and individualize then from there. But I prefer the former kind Setup that even if you do not individualize that is offered to all, always not something that auto-fichiers images in a useful and meaningful way. I do not customize folder names myself, so this just just there.

  • Create the new folder and showed it in the folder Panel

    In my plugin, I want to create a subdirectory in my picture folder and showed in the folder Panel.

    The first part was not easy...

    LrFileUtils.createAllDirectories(destinationFolder)

    After it is created, it is the empty dishes.

    Question: How can I get this new folder in the folders Panel.

    Even there I try "synchronize folder.." it does not appear.

    I think that the only way to get the file appear in the files via a plugin Panel is to import a photo of this file, using catalog:addPhoto ().

  • Import automatically creates a new folder and I don't want it.

    Hey there ' All,.

    Lightroom is using for a few years now, and I understood the thought. just installed it on a new computer and now when I import new photos from an SD card, the program creates files and I don't want it. I manually create my own records and want to disable this feature. Anyone know how?

    Thank you.

    Barry

    Hi Barry,.

    Please uncheck the option in the subfolder and select one folder in the Destination panel in the import dialog box.

    Let me know if it helps.

    ~ UL

  • I moved the files in Lightroom 5 from one drive to another (created the new folder and dragged).  Now I see warning of metadata.  What has caused this?  Can I import or rewrite the difficulty catalogue?

    I am reorganizing lots of photos in Lightroom 5.  Some who were on my hard drive, I moved to an external drive.  I did all this in Lightroom.  I created a new folder on the hard drive, external, selected all the images in the folder on the hard disk, trained to the new folder.  Made sure they were there.  Then deleted the folder on the hard drive.  When I looked in Windows Explorer, the (empty) folder was still on the hard drive, so I deleted it there too.  Now, I get the warning on the images in the new folder metadata were changed in Lightroom and an external program.  The options are to import from disk or rewrite from the catalog.  I would like to know what caused this and how to fix it.

    Thanks for the clarification of Nancy.

    The warning of "metadata conflicts" is an indication that Lightroom "sees" a discrepancy between the data in its catalog and the data in the image file (or in the xmp file) on the real situation which could be due to permissions at the new location.

    You should choose the option to replace the parameters, that is, rewrite in the Lightroom Catalog can write changes to metadata of the catalog itself.

    (Import of the disc would cancel the metadata changes that you did until now)

  • Just recently I have not been able to move the folder on my desktop. I have to copy and paste it into a new folder, and then delete the old on.

    Just recently I have not been able to move the folder on my desktop. I save videos to my office then then move in different folders, but now need to copy and paste, then remove the video from office.  Around the same time, when I try to use help I have Windows Help cannot start.  So please HELP.  Using Win7.

    Hello

    1. Did you of recent changes made to your computer that caused the problem?
    2. It happens that the Office? Have you tried with Documents and other readers?

    Step 1: File system [SFC] Checker

    Try to run a scan of the file system [SFC] checker on the computer that will replace missing or corrupt files & check if the problem persists.

    How to use the System File Checker tool to fix the system files missing or corrupted on Windows Vista or Windows 7

    http://support.Microsoft.com/kb/929833

    Step 2: Run a virus scan to check if there are infections on the computer:

    Microsoft safety scanner

    http://www.Microsoft.com/security/scanner/en-us/default.aspx

    Note: If infections are detected during the scan, there is a risk of data loss because infected files will be deleted.

    Step 3: Follow the instructions in the article to fix the problem of files and folders in Windows:

    Diagnose and repair Windows files and folders problems automatically

    http://support.Microsoft.com/mats/windows_file_and_folder_diag/

    For more information, follow the instructions in the article to improve the performance of Windows 7:

    Optimize Windows 7 for better performance

    http://Windows.Microsoft.com/is-is/Windows7/optimize-Windows-7-for-better-performance

    It will be useful.

Maybe you are looking for

  • Hour of Code

    When I go to the Microsoft Virtual Academy and click one of the links/videos they have, a loading page/bar appears and stays like that for a while. A few days ago, I was able to access the content without any complications. But as of today, I get the

  • This is a bad messeenger

    because not to sing in my email

  • Stacked waveform diagram

    Hello world I merged three signals and traces on a waveform graph.  There are three graphs the stacked on top each other so I know it works.  I was wondering if there is a way to plot them on a single diagram?  Is it something in the properties I'm m

  • Acer Aspire D255E turns on, displays on screen, then stops in a few seconds

    I just bought an Acer Aspire D255E with a cracked screen.  I tested it and it worked fine.  Replaced the screen with a new brand, and the result is that it turns on, shows the opening screen, flashes what looks like the screen you get when you stop a

  • Open a word with extn docx file using windows xp 2002

    My home PC's with windows XP 2002. Documents received in the version other than the 2002 version and above could not be opened. Please help me to open a word with extn (.docx) file using windows xp 2002