Hi,
I'm stuck.
I'm trying to create a .cmd file to delete a VMDK file.
ex: delete.cmd viserver vm "[TEST_Sequence_Dev] SEQDEV9/SEQDEV9_1.vmdk"
delete.cmd
@echo off
REM VCENTER=%1
REM VM=%2=Nom de la VM
REM HardDisk=%3=Chemin et Nom du disque
powershell.exe -command "&'C:\Users\malabelle\Desktop\tests\delete-vmdk\delete-vmdk.ps1' %1 %2 %3"
delete-vmdk.ps1
Add-PSSnapin "Vmware.VimAutomation.Core"
$Vcenter = $args[0]
Connect-VIserver $Vcenter | Out-Null
$VM = $args[1]
$HardDisk = $args[2]
$status = (get-VM $VM).PowerState
if($status -eq "PoweredOff")
{Get-HardDisk -VM $VM | Where {$_.Filename -eq $HardDisk} | Remove-HardDisk -DeletePermanently -Confirm:$false}
else {"Veuillez fermer la machine pour procéder"}
When I run it manually:
Get-HardDisk -VM SEQDEV9 | Where {$_.Filename -eq "[TEST_Sequence_Dev] SEQDEV9/SEQDEV9_1.vmdk"} | Remove-HardDisk -DeletePermanently -Confirm:$false
it works.
When I run it with the batch file, it connects to the viserver, take 3 seconds, and nothing (return to the prompt)
Any Idea?
The problem is caused by the blank in the vmdk filename.
Try calling your cmd like this (single quotes inside the double qoutes for the third argument).
delete.cmd viserver vm "'[TEST_Sequence_Dev] SEQDEV9/SEQDEV9_1.vmdk'"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Are you running the batch file with an account that has sufficient rights on the vCenter server?
Regards, Robert
Yes I run it with admin rights.
I just tried modifiyng the ps1 to add -user -password, same thing.
thanks
I just tried to specify the filename directly in the ps1 and it worked... So the problem is in the command line... Do you have an idea? thanks
Add-PSSnapin "Vmware.VimAutomation.Core"
$Vcenter = $args[0]
Connect-VIserver $Vcenter | Out-Null
$VM = $args[1]
$HardDisk = $args[2]
$status = (get-VM $VM).PowerState
if($status -eq "PoweredOff")
{Get-HardDisk -VM $VM | Where {$_.Filename -eq "[TEST_Sequence_Dev] SEQDEV9/SEQDEV9_1.vmdk"} | Remove-HardDisk -DeletePermanently -Confirm:$false}
else {"Veuillez fermer la machine pour procéder"}
The problem is caused by the blank in the vmdk filename.
Try calling your cmd like this (single quotes inside the double qoutes for the third argument).
delete.cmd viserver vm "'[TEST_Sequence_Dev] SEQDEV9/SEQDEV9_1.vmdk'"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You're right lol
Thanks Luc