Script to remove hard drives as HDD1 of VM and Add again.

Hi, I tried to write the script to stop the virtual machine and then remove the hard drives as HDD1 and then again add back, here's my script (not yet completed)

$vmname = testvm02

Get-VM-name $vmname | %{

Write-Host 'Stop of the VM' $vmname

$vmname | Get-VMGuest | where {$_.} State - eq "Running"} | Stop-VMGuest-confirm: $false

$HDD = get-disk hard - VM $vmname | Hard drive remove

above script remove all disks that are attached to the VM I want not, I want to only remove that hard hard disks Disk1.

Can someone please help me to write this script

its been... Thanks for all the entries

Here is the script...

$vmname = get-Content - Path "VM.txt".

{foreach ($VM to $Vmname)

$getVM = get-VM-name $VM

Write-Host 'Stop of the VM' $VM

$getVM | Get-VMGuest | where {$_.} State - eq "Running"} | Stop-VMGuest-confirm: $false

{}

#Wait for the virtual machine to poweroff

$Shutdownvm = get-VM-name $VM

$powerstaus = $Shutdownvm.PowerState

Write-host "pending the judgment of the $VM.

sleep 5

} until ($powerstaus - eq "PoweredOff")

$HDDfile = get-disk hard - VM $VM | Where-Object {$_.} Name - not "Hard Disk 1'} | Select file name

#$HDDpath = $HDDFile.FileName

Write-Host "Remove the hard disks in the virtual machine" $VM

Get-disk hard - VM $VM | Where-Object {$_.} Name - not "Hard Disk 1'} | Remove-hard drive - confirm: $false

{foreach ($HDD to $HDDfile)

$HDDpath = $HDD. File name

Write-Host 'Add the disk to the VM' $VM

New-disk-hard - VM $VM - DiskPath '$HDDpath '.

}

Write-Host 'starting VM' $VM

Start-VM $getvm

}

Tags: VMware

Similar Questions

  • Remove-hard drive, cant pass a string to it, is there another way?

    I was thinking of using Get-hard drive and then channelling it to Remove-hard drive, but I don't know how to get only the text VMDK * wink *. The below script used to work a few months ago, I'm not sure what has changed, no upgrade were made.

    The code in question:

    $DisksToRemove = (get - VM VM1, VM2, VM3 |) Get - Harddisk)

    foreach ($disk in $DisksToRemove)

    {

    if($Disk.) Filename-comme "* wink *")

    {

    Remove-hard drive - HDD $disk. Filename-confirm: $false

    Write-Host "Removed:"-to the first 'green' plan ".

    Write-Host $disk. File name

    }

    }

    In addition, you could add this to your existing code and it should work

    $DisksToRemove = (get - VM VM1, VM2, VM3 |) Get - Harddisk)

    foreach ($disk in $DisksToRemove)

    {

    if($Disk.) Filename-comme "* wink *")

    {

    $disk: Remove-hard drive - confirm: $false

    Write-Host "Removed:"-to the first 'green' plan ".

    Write-Host $disk. File name

    }

    }

  • Remove-hard drive - confirm the $false woes

    Hello

    Having some problems getting this working (4.1 u1); I was wondering if some soul could help.

    Remove-hard drive - whatif - confirm $false - hard drive (Get-disk hard - VM vTest2 |?) {} $_. ({Name - eq ' Hard disk 2 "})

    This is my code at the moment (see above), I try to get the - confirm the value of the $false according to the document: http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Remove-HardDisk.html

    I can get it works fine without the - confirm $false, but he invites me to a dialogue of the type "are you sure y/n"; as I need to run it in a script I have to disable the confirmation.  Please can someone help me with what Miss me?

    For reference, I pulled the code here:

    http://communities.VMware.com/thread/315086

    Thank you!

    Leon.

    That must be - confirmed: $false

  • How to install my game on my removable hard drive.

    I need to know if I can install my game on my removable hard drive and if so, how? Thank you

    Hi shananagan,

    Yes, it is possible to install a program on an external hard drive.

    Most of the program\game installation wizard allows you to choose a destination drive to install on; You can choose your external hard drive for the installation files reside.

    If the game setup button does not give you a choice, in this case you cannot install it on the external hard drive.

    Normally, Small\flash games can be installed on the external hard drive.

    Note: When you install a program on the external hard drive, it made an entry in the registry of the operating system, the installed program may or may not work when the external hard drive is disconnected and re connected.

    Thank you, and in what concerns:

    Ajay K

    Microsoft Answers Support Engineer

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • I want to give a permanent Player ID removable hard drive

    I have several removable hard drives. What I want to do is to put it up so that when I plug a drive in

    the computer, it will use a drive letter of my choice, not what drive letter is free.

    Example; Removable disk ID 1 would drive X: 2 = y and so on.

    Is this possible?

    Go in run, type: diskmgmt.msc

    Msc, L.click the disk, go to actions, all, search & select: "change path /"

    name' set did. In addition, select the 'active' brand if it exists.

  • OK, I did something "stupid." The hard drive on my computer was full so I copied my pictures to a removable hard drive. Then I deleted them on my mac. I also wanted a new installation of LR, so I uninstalled that too. I reloaded LR and reloaded my drink "

    OK, I did something "stupid." The hard drive on my computer was full so I copied my pictures to a removable hard drive. Then I deleted them on my mac. I also wanted a new installation of LR, so I uninstalled that too. I reloaded LR and reloaded my 'catalogue', but I don't know how to do so that he can look at the pictures on my external HD help!

    wendyh81856794 wrote:

    Oh, okay, I think I got it. If the folders on my computer with the? Use the LR 'catalogue' on my computer, and when I reconnect them, LR uses the 'catalogue' on my external hard drive?

    No Lightroom does not use a different catalog.

    We discuss records, are we not? In the original catalog, you have a folder with one? mark, say C:\Photos, and you used your operating system to move it to F:\Photos. Lightroom has this record showing under the C:\ drive. As soon as you make the reconnection, Lightroom indicates the folder in the drive F:\.

    Oh, and is there a way to do all the files at once? or what I need to do one at a time?

    See Figure 4 and the corresponding text in the document I linked to.

  • Why do not the remove-hard drive remove a disc with a new SCSI controller?

    Hi PowerCLI gurus,

    I try to use PowerCLI to automate the solution for article configuration of disks to use VMware Paravirtual (PVSCSI) SCSI adapters (1010398).

    Remove-hard drive sometimes gives me a misleading error when I use it to remove a hard drive with a new SCSI controller.

    The FlatHardDisk specified 'Hard disk 3' no longer exists, or never existed.

    Can anyone here explain the error?

    My version of vCenter server is 5.1.0.

    My PowerCLI version is 2.0.

    Here's what I've done to reproduce the error.

    First of all, I connect to vCenter and stop the virtual machine.

    $TestVM = 'TESTVM '.

    $TestServer = ' vcenter - test.local ".

    SE connect-VIServer-Server $TestServer

    Stop-VM - $TestVM VM - confirm: $false

    I add a new hard drive and store it in a variable so I can refer to it for the next steps.

    New hard drive '.

    -VM $TestVM '

    -Persistent persistence"

    -Flat DiskType '

    CapacityKB - 1024'

    StorageFormat - thin '

    -OutVariable TempDisk

    I make a note of its name.

    $TempDisk.Name

    Because my VM already has 2 discs, the output is "hard drive 3.

    Then I add a new SCSI controller on the hard drive.

    New SCSI controller.

    Hard drive - $TempDisk '

    -Type ParaVirtual '

    NoSharing - BusSharingMode

    Now, I try to remove the hard drive from the variable to remove the disc.

    Remove-hard drive - hard drive $TempDisk - DeletePermanently-confirm: $false

    It fails with an error that says "Hard drive 3" has already been removed.

    Remove HDD: 12/02/2014-18:51:33 remove-hard drive the FlatHardDisk specified 'Hard disk 3' no longer exists, or never existed.

    On line: 1 char: 1

    + Delete-hard drive - hard drive $TempDisk - DeletePermanently-confirm: $false

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo: ObjectNotFound: (3:FlatHardDiskImpl drive) [Remove-hard drive], VimException

    + FullyQualifiedErrorId: Client20_VirtualDeviceServiceImpl_TryValidateDeviceExists_DeviceDoesNotExist, VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveHardDisk

    But I see that there are still "hard drive 3"!

    Get-disk hard - VM $TestVM - name 'hard drive 3.

    CapacityGB persistence Filename

    ----------      -----------                                    --------

    0.001 persist... B-DATA-01] TESTVM/TESTVM_9.vmdk

    Is this a bug or am I missing something?

    I don't think that the cmdlet uses actually the UID, but more likely a MoRef to the vSphere object that represents the hard disk.

    Remember that under the covers most of the PowerCLI cmdlets do calls to the vSphere API.

    Change the Uid, property value indicates that the hard drive connected to the new controller is a new and different purpose.

    And this explains why the hard drive remove does not work with the original hard disk object, it no longer exists.

  • Cancel an increase in data store on removable hard drive

    Hello, I was just wondering, but I was messing around trying to find the way on an empty stomach for manually copying the VM to a RDX removable hard drive and decided to try to increase the size of the data with the RDX hard disk store.  I was wondering if there is a way to cancel this increase in size of the data store.  When I remove the RDX drive, it gives me an error saying no data store has been created but still work in the VM.  Any help would be appreciated.

    Welcome to the community,

    I understand thi correctly. You have added the RDX as a measure for the data store local drive!

    There is no way to remove a measure. You will need to evacuate the data store (i.e. save virtual machines), remove the extended data store and create a new.

    André

    BTW: With product (edition/version/version) are you using?

  • After Vista update cannot find the external hard drive, AutoPlay does not work, and new unusable disk appears under my computer

    After Vista update cannot find the external hard drive, AutoPlay does not work, and new unusable disk appears under my computer. Also I can't 'manage' my computer because I do not have "permissions". I tried a fix he 45071 and it did nothing.

    Applications, (Norton and McAfee) (including free evaluation versions are notorious for not not upgrade (or uninstalling) itself.) If NIS has been installed for 3 years, you have NIS update at least once and maybe twice (e.g., NIS 2009 > NIS 2010 > NIS 2011).

    [You may want to print these instructions for reference offline. If a step said to reboot, reboot.]

    1. download the Norton Removal Tool, save it to your desktop: ftp://ftp.symantec.com/public/english_us_canada/removal_tools/Norton_Removal_Tool.exe

    2. close all open applications (that is, anything with an icon on the taskbar).

    3. After completing some you have a copy of your handy product key, uninstall all Norton software (including LiveUpdate and everything Norton Add ons) viaControl Panel | Programs | Uninstall a program (or Control Panel |) Programs and features, if you are using the classic view).

    4 IMPORTANT! -Online activate Windows Firewall immediately after the restart.

    NB: Now you're "working without a net": no to ANYTHING else online (e.g., navigation, reading e-mail, chat) until you have completed step #7 below!

    5. right click on the file that you saved in step #1 above, and then select run as administrator.  DO TAP not your keyboard until the race ends, then restart.

    6. do a clean install of NIS 2011 (using your product ID, if need be) & reboot. CF. http://www.symantec.com/norton/support/kb/web_view.jsp?wv_type=public_web&docurl=20080514162318EN

    NOTE: Do NOT activate or install additional modules of Norton (for example, Norton Anti-Phishing) immediately.

    7. manually and repeatedly run LiveUpdate (Norton) until you get a prompt "no update more".

    8. open Internet Explorer (only) to http://support.microsoft.com/kb/923737 & run the difficulty.

    9. open Internet Explorer (only) to http://support.microsoft.com/kb/971058 & run that set it by DEFAULT and modes and AGGRESSIVE. [1]

    10. restart once again & test.

    NB: Installation KB971029 disables AutoRun/autoplay on USB connected but not 'brilliant media' external drives (i.e., CDs & DVDs). See http://blogs.technet.com/b/msrc/archive/2011/02/08/deeper-insight-into-the-security-advisory-967940-update.aspx

    ~~~~~~~~~~~~~~~~~~~~~~~~
    [1] full Disclosure: the difficulty operating in AGGRESSIVE mode will remove your update history but not list the updates installed in Add/Remove Programs (Windows XP) or installed updates.

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • I lost my product key of Windows XP. I had to wipe my hard drive due to the virus, and now I can't activate Windows because I lost the key.

    I lost my product key. I had to wipe my hard drive due to the virus and I installed win xp pro back. now, I can not activate my copy. This is the disc that came with the computer. its windows xp pro sp/2 from dell. I've tried everything I know using keyfinders and research on the disk. the keyfinders and drive both will eventually go wrong. What can I do next?

    original title: lost product key

    Hello

    Contact Microsoft telephone support on this.

    http://support.Microsoft.com/contactus

    For more information visit: How to replace Microsoft or hardware, packs software service to order and replace product manuals

  • Replaced the hard drive, need help with drivers and utilities!

    Hello

    Yesterday, I replaced my old hard drive with a new WD, and I reinstalled Windows Vista.  Everything goes fine until I jumped in the utilities and drivers (Resource CD) supplied with the laptop.  I guess I thought that the CD all the work, would do to reinstall all the necessary drivers and utilities...  Now I'm stuck with a laptop computer that cannot connect to the internet, and the screen is too big.  I don't know there is more wrong with my laptop than meets the eye.  On the CD of drivers & utilities there the list of drivers and some of them have check marks, others do not.  I tried following some online course on which those who/what order to upload, but I don't even have some recommended drivers on the Dell.com site (specific to my Inpiron 1545 model)!  I know that I could download them immediately the site, but I don't even have wifi to do.

    In addition, I read the performance of a Dell Factory Image Restore and I tried it.  When I get the black screen with no option, I have to click on "Repair computer" but the option is not available either... I thought that maybe it would be an easy way to restore my laptop (readers and all) to the original settings.  Maybe the option is not there because my computer is practically empty, with nothing to restore? All I have on my laptop at the moment is Windows Vista 64 bits and drivers a couple that I don't know much.

    Bit of help and advice would be great.

    Anna

    Click on the link below, Guides of operating system Installation.

  • I copy / paste a file from a hard drive to a usb port and now I lost the USB I get the hard drive?

    I move a file from a hard drive to a usb port and now I lost the USB I get the hard drive

    Tuesday, June 26, 2012 13:21:43 + 0000, MarvinBester wrote:

    I move a file from a hard drive to a usb port and now I lost the USB I get the hard drive

    "Deleting" a file does not actually delete it marks just the space
    also available to be used. There are third-party programs that can
    sometimes recover deleted files. The problem is that the space used by
    the file is likely to be replaced very quickly, and it makes
    the unrecoverable file.

    So your chances of successfully recover this file are decent if you
    Try it again immediately after the deletion of it and go quickly
    downhill from there. If you have used the computer since then (for
    example to write this question and read this answer), your chances may
    be very poor now.

    But if the file is large enough, it's still worth a try. Stop
    using the computer in question immediately, if you have not done
    already. Download an undelete program (and here's one:)
    http://www3.TELUS.NET/mikebike/restoration.html but there are several
    others to choose from; Do a search) on a friend's computer (do not
    it on yours because that would overwrite the files you want
    Undelete) and bring it to you on a CD or thumb drive to try.

    If that fails, your only recourse is to bring or send the disc
    a company of professional file recovery. This kind of service is very
    expensive and may or may not work in your case.

    Ken Blake, Microsoft MVP

  • What I would do is change the hard drives for some more great and maybe change the CPU. Is it possible to re - install the generator in system because I'm not changing the motherboard?

    I'm running an integrator system Windows 7 64 bit on an older system. What I would do is change the hard drives for some more great and maybe change the CPU. Is it possible to re - install the generator in system because I'm not changing the motherboard?

    Original title: Windows 7 OEM System Builder

    I'm running an integrator system Windows 7 64 bit on an older system. What I would do is change the hard drives for some more great and maybe change the CPU. Is it possible to re - install the generator in system because I'm not changing the motherboard?

    Yes, you can reinstall Windows 7 OEM System Builder License on the new hard drive with the new processor.

    It will not be a problem in this case, since you don't "move" installation, you are doing a new installation. The less it will take is activation of the phone, as you change the hard drive:

    How to activate Windows 7 manually (activate by phone)
     
    1) click Start and in the search for box type: slui.exe 4
     
    (2) press the ENTER"" key.
     
    (3) select your "country" in the list.
     
    (4) choose the option "activate phone".
     
    (5) stay on the phone (do not select/press all options) and wait for a person to help you with the activation.
     
    (6) explain your problem clearly to the support person.
     
    http://support.Microsoft.com/kb/950929/en-us

  • I have a macbook pro with only 128 GB of hard drive. I installed lightroom and all my photos on an external hard drive. Can I keep my library on the external hard drive also lightroom?

    I have a macbook pro with only 128 GB of hard drive. I installed lightroom and all my photos on an external hard drive. Can I keep my library on the external hard drive also lightroom?

    Yes. Find LR catalog file in Edit/settings/general catalogue. Close LR and go to this place. The catalog file is one that ends by .lrcat - move it where you want. Beside the .lrcat file is a subfolder called Previews.lrdata. You can move, but if you don't not LR will generate new insights. Double-click the .lrcat file in her new home and LR will open with this catalogue. Set preferences in more recent catalogue.

  • I bought a whole new office 27 "Mac provided with Adobe CS6. Everything worked like a charm until the 1 TB hard drive, developed a bad sector and the Apple Store reinstalled a new I had extended warranty with them. The recycled player I

    I bought a whole new office 27 "Mac provided with Adobe CS6. Everything worked like a charm until the 1 TB hard drive, developed a bad sector and the Apple Store reinstalled a new I had extended warranty with them. They are recycled the disc immediately (like crazy, I don't ask for this return to get the data off it.) But fortunately, I have all my data on CrashPlan. I downloaded it and it was working fine except that I downloaded it on the desk and not the original location so he had succeed. I also have an external 1.5 TB drive that I wanted to make it bootable, so I installed Mavericks 10.9.3. Then I advanced and installed on disk newly installed too.

    I think that because I have a new reader that adobe thinks, I have a new computer. I bought the 27 "Mac new on Ebay and it came loaded with the software, including CS6. I have a serial number for CS6, but Adobe says that it was not valid. (I've owned CS2 and CS4 now CS6 that came preloaded on the Mac by the seller who told me that the software has been registered for the Mac?

    I'll re - download the backup to the original location but this time (I still don't think that it will work with Adobe.) What can I do about it?

    iMac 27 inches, end of 2012

    Processor 3.2 GHz Intel Core i5

    Memory 32 GB 1600 MHz DDR3

    Graphics  NVIDIA GeForce GTX 1024 MB 675MX

    Software  OS X 10.9.3 (13D 65) @.

    You must contact Adobe Support by chat or phone when you have the serial number and activation problems.

    Here is a link to a page with options to help make contact:

    http://www.Adobe.com/support/download-install/supportinfo/

Maybe you are looking for