VMware Cloud Community
yhaseeb
Contributor
Contributor
Jump to solution

Any way to eject all media?

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!

0 Kudos
1 Solution

Accepted Solutions
Pavel_Dimitrov
VMware Employee
VMware Employee
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
dmilov
VMware Employee
VMware Employee
Jump to solution

Hi,

You should iterate through all vms and call Eject for each one:

foreach($vm in $vms) {

     $vm.ExtensionData.EjectMedia()

}

Regards,

Dimitar Milov

0 Kudos
Pavel_Dimitrov
VMware Employee
VMware Employee
Jump to solution

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

0 Kudos
yhaseeb
Contributor
Contributor
Jump to solution

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! Smiley Happy any other ideas?

Thank You!

Kevin

0 Kudos
yhaseeb
Contributor
Contributor
Jump to solution

doh, nevermind, my session had expired.  Your solution worked perfectly! Thank You! Smiley Happy

0 Kudos