Hi all,
Been banging my head with this one its drving me mad hopefully someone can help please. I am using LucD excellent Orphaned files and folders - Spring cleaning - LucD notes script to identify orphaned VMDK files. I have ran the script and exported the results into a CSV file.
What I need to do now is to run a script that will move every VMDK in the csv file to another datastore. I am struggling to get the powercli command correct and I am hoping someone will be able to help please.
I have tried these:
Move-HardDisk -Harddisk (Import-Csv C:\csvfilename.csv | %{$_.Name})
Cannot bind parameter 'HardDisk'. Cannot convert the "filename_0001.vmdk" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.HardDisk"
And
Get-HardDisk -Name (Import-Csv C:\Users\DeanE\Documents\ListofDeletedDC2_A_T1_SRM_PL003VMDKs.csv | %{$_.Name})
Get-HardDisk Please specify at least one of the following: Path, Datastore, VirtualMachine, Template or Snapshot.
And
Get-HardDisk -Datastore DatastoreName -Name (Import-Csv C:\csvfilename.csv | %{$_.Name})
Parameter set cannot be resolved using the specified named parameters.
Any help would be greatly appreciated please.
Thanks very much
Ok, had another look.
The following seems to work for me, at least for the entries that have `flat` in the VMDK filename
Import-Csv c:\orphan.csv -UseCulture | %{
$ds = $_.Extents.Split(']')[0].Trim('[')
$dsPath = $_.Extents.Replace('-flat','')
Get-HardDisk -Datastore $ds -DatastorePath $dsPath
}
If you have entries in the CSV for which it doesn´t work, let me know what is in the Extents field.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you already try with the Path parameter instead of the Name parameter ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No sorry, will give that a whirl now.
So the headers I get in the csv file are
"Extents","Name","Thin","CapacityKB","Folder","Size"
the extents field gives the following results:
[Datastore Name] filename-00001-delta.vmdk
Tried running this:
Move-HardDisk -Harddisk (Import-Csv C:\vmdk.csv | %{$_.Extents})
Cannot bind parameter 'HardDisk'. Cannot convert the value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.HardDisk".
Does this work ?
Import-Csv -DatastorePath 'C:\Users\DeanE\Documents\ListofDeletedDC2_A_T1_SRM_PL003VMDKs.csv' | %{
Get-HardDisk -Path $_.Extents
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It gives me this error for each line on the csv
Get-HardDisk : Cannot validate argument on parameter 'Path'. The argument is null. Supply a non-null argument and try the command again.
Get-HardDisk The specified path filename.vmdk is not valid. Only 'VimDatastore' provider paths are valid for the Path parameter
That should have been Extents, not Extent
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, yeah I noticed that still get this error.
Get-HardDisk : 17/07/2015 10:12:40 Get-HardDisk The specified path '[datastore] filename-000010-delta.vmdk' is not valid. Only 'VimDatastore' provider
paths are valid for the Path parameter.
At C:\Users\DeanE\Documents\Get-VMDKsfromcsv.ps1:6 char:5
+ Get-HardDisk -Path $_.Extents
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (VMware.VimAutom...DatastoreItem[]:DatastoreItem[]) [Get-HardDisk], VimException
+ FullyQualifiedErrorId : Core_GetVirtualHardDisk_TryValidateProviderPath_InvalidPathProvider,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetHardDisk
And with DatastorePath instead of Path ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Different error this time:
Get-HardDisk Value cannot be found for the mandatory parameter Datastore
Ok, had another look.
The following seems to work for me, at least for the entries that have `flat` in the VMDK filename
Import-Csv c:\orphan.csv -UseCulture | %{
$ds = $_.Extents.Split(']')[0].Trim('[')
$dsPath = $_.Extents.Replace('-flat','')
Get-HardDisk -Datastore $ds -DatastorePath $dsPath
}
If you have entries in the CSV for which it doesn´t work, let me know what is in the Extents field.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You my friend are a legend!!! This is what I used as all the files listed are "-delta". Thank you very much for taking the time to help, its very much appreciated.
Import-Csv C:\orphan.csv -UseCulture | %{
$ds = $_.Extents.Split(']')[0].Trim('[')
$dsPath = $_.Extents.Replace('-delta','')
Get-HardDisk -Datastore $ds -DatastorePath $dsPath
} | Move-HardDisk -Datastore datastorename
I've been looking at a similar thing, so going to give this a go. I generate the csv from the RVTools Healthcheck page and we have a LOT of orphan files. I'd like to output the filename, file size, start and finish times to a text file as well. I'm just starting to get my head around PowerCLi and enjoying the power it brings!