Hi,
I am trying to eject the media of all vm's in an org but I am having trouble. Is there an easy way to do this?
As an example with just one vm.
PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $vms
Name Status GuestOSFullName CpuCount MemoryGB
---- ------ --------------- -------- --------
vcenter PoweredOn Microsoft Windows Server 2008 R2 (64-... 2 4.000
PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $vms.ExtensionData.EjectMedia()
Cannot find an overload for "EjectMedia" and the argument count: "0".
At line:1 char:30
+ $vms.ExtensionData.EjectMedia <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
I am not great at all with powercli so forgive me if this is an easy one
Thanks!
EjectMedia expects as a parameter the reference to the detached media. try something like:
$media = Get-Media
foreach ($vm in $vms){
$media | % {$vm.ExtensionData.EjectMedia($_.ExtensionData.Href)}
}
I expect this to detach all attached media from each VM in $vms
Regards,
Pavel Dimitrov
Hi,
You should iterate through all vms and call Eject for each one:
foreach($vm in $vms) {
$vm.ExtensionData.EjectMedia()
}
Regards,
Dimitar Milov
EjectMedia expects as a parameter the reference to the detached media. try something like:
$media = Get-Media
foreach ($vm in $vms){
$media | % {$vm.ExtensionData.EjectMedia($_.ExtensionData.Href)}
}
I expect this to detach all attached media from each VM in $vms
Regards,
Pavel Dimitrov
Hi Pavel,
When I run that script I get a bunch of :
Exception calling "EjectMedia" with "1" argument(s): "Access is forbidden"
At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\scripts\dumpmedia.ps1:5 char:45
+ $media | % {$vm.ExtensionData.EjectMedia <<<< ($_.ExtensionData.Href)}
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
One for every media file I have in my catalogs. It is looking closer though! any other ideas?
Thank You!
Kevin
doh, nevermind, my session had expired. Your solution worked perfectly! Thank You!