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



Tags: VMware

Similar Questions

  • 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, 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.


    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.

  • 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


  • Remove-hard drive - confirm the $false woes


    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:

    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:

    Thank you!


    That must be - confirmed: $false

  • 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.


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

  • External hard drive does not work. Is there another way I could solve the problem without formatting the external hard drive?

    My external hard drive works. I tried to plug and when I tried to open it, it says to format the drive until I could use it. Everything works well as when I plugged the USB icon shown on the screen. When I check the disk management, it showed that the partition of the drive is there.

    I tried to change the drive letters, but still having the same problem. I also tried to run the disk check on the command prompt and the properties of the drive, but it still can not because there is error popping up saying that the disk check cannot be performed because Windows cannot access the disk.

    Is there another way I could solve the problem without formatting the external hard drive?

    I tried the first step in troubleshooting the hard drive, but it gives a
    error in saying that "hardware changes might not have been detected.

    So I tried the second method, and when I click on the "Check now" button his
    gives an error saying that "the disk check cannot be performed because .
    Windows can not access the disk".".

    So is there any other way or option?

    Thank you


  • I accidentally deleted files from a flash drive without looking at what they were; is there a way to view a journal detailing which files have been deleted?

    I accidentally deleted files from a flash drive without looking at what they were; is there a way to view a history of the measures taken with regard to the changes to the file?  Already I have saved new files on my flash drive so I do not expect to recover the lost files, I just want to know which have been deleted.


    You can use File Undelete tools to see which files are recoverable without actually restoring courses.

    Recuva - free

    Recuva Forums - excellent help here

    Check the trash.

    I hope this helps. Rob - bicycle - Mark Twain said it is good.

  • HP color laserjet pro M476: remove hard drive - HP color laserjet pro M476

    How can I remove the hard drive of this device (which no longer works and has been replaced by another device) so that I can have the HARD drive physically destroyed?

    I guess that all the items are stored on the trainer. There is no residual files when the printer is off, and none of the scanning functions will work even if the trainer is moved to a working machine because network credentials are not the same.

  • HP Pavilion p6620f PC: impossible to remove Hard Drive Cage to desktop


    I am trying to replace the hard drive on my desktop, but I currently have a problem with the removal of the metal cage that surrounds the hard drive. This is the recommended method to replace the hard drive, according to these instructions:

    I'm stuck on step 13 for this manual in particular. I press the "#1" lock and pull forward, but he's not slide forward. I'm not sure what hurts me, but the thing does not move. Guys do you have an idea what I can do wrong? Thank you.


    Drag the HARD drive cage to the top of the PC while pressing the lock.

    Then pull the cage out of the tower.

    I have a h8 1380t with the same HARD drive cage.


  • can I reinstall vista, removed hard drive?

    I bought a laptop computer with a hard drive deleted, if I get a new hard then re - install vista if they product key sticker is on the bottom of the laptop?


    Licenses, Activation and hardware drivers problems do not work how the other poster tells you

    If this hard drive was put in another computer, it would not work for 2 reasonns.

    1, it will NOT be activated until the preinstaled license OEM, a computer brand, DELL, HP, etc, is related to the original machine it was installed on

    2. it would not in all the probability of starting as this removed hard disk motherboard drivers required in order for it to work on your laptop, not another machine

    many people take a hard drive out so that they can keep them on private data they sell laptop

    also with regard to what the other poster told you about the recovery partition:

    It won't work that on YOUR laptop, NOT another machine, the hard disk may be implemented

    Here's how to reinstall Vista on your laptop:

    Contact the manufacturer of the laptop computer and ask them to send you to vista recovery disks to reinstall the operating system back as it was when you bought it

    they do it for a nominal cost of $

    or borrow a vista microsoft dvd; not a HP, Acer recovery disk etc and use your product key

    Make sure that you borrow the correct 32-bit or 64-bit microsoft dvd to your computer

    they contain all versions of vista

    This is the product key that determines which version of vista is installed

  • Removed hard drive migration


    I have a question - can I use the Migration Wizard for a USB-Attached hard drive?

    Why I ask: the wife had a MacBook Pro who succumbs to a horrible death - I think that the MSC ultimately failed (he had more than 9 years).  I pulled the hard drive (because the computer does not even) and put it in a box 2.5 "USB.  She has a new MacBook Air that we want to migrate its photos, mail and iTunes library to.  If necessary, I will copy them by hand - but if there is a way to do this in the Migration Wizard I would use that - or rather IT will use that!

    Thank you


    Yes, you can use an external drive to migrate data using Migration Wizard. Just point to it!

    Alternatively, as you said, you can copy by hand.

  • Equium L20-264, do not recognize the removable hard drive

    Can anyone help. I haven't bought a nice no notebook on the weekend and you want to get the stuff to my Lacie hard drive that I use on my mac to work on.

    Last night I plugged the drive (USB with PSU) and messages little came "new device found" then "works and is ready to use" However he didn't appear in the list of drive in the my computer window. Went to Device Manager and found it listed checked there, he worked and what everything was soft but still no joy to be able to find it or mount it or access it. I tried all the suggestions help, and eventually just turned it off.

    Also, for some reason, it lists the location as 0 istead of as USB 2 or whatever port when I plug another accessory, this would have something to do with it? I need to rename the disk or something?

    Can anyone help?


    Hi the GATS.

    I'm not too knowledgable about MACs, but I think they use a different file for computers structure and that the files can be copied directly to a PC without first being "converted" to make them compatible. I also suspect that your Lacie is formatted to be used with a MAC, and therefore your XP operating system may not identify as a hard drive so does not show in my computer.

    I think you can get some freeware to convert your MAC files, then I suggest Googling to see what you can find.

    Kind regards

Maybe you are looking for