mark_chuman
Hot Shot
Hot Shot

-RunAsync available with Remove-Host?

Seems to work fine with set-vmhost, but not sure why it doesn't seem available with remove-host?

Reply
0 Kudos
mark_chuman
Hot Shot
Hot Shot

example

PowerCLI C:\Scripts\vCenter\migration> foreach ($vmhost in $CSVhosts) {remove-vmhost -VMhost $vmhost.name -confirm:$fals

e -RunAsync}

Remove-VMHost : A parameter cannot be found that matches parameter name 'RunAsync'.

At line:1 char:84

+ ... confirm:$false -RunAsync}

+                    ~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Remove-VMHost], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveVMHost

Reply
0 Kudos
LucD
Leadership
Leadership

Why the RunAsync is not available on the Remove-VMHost cmdlet, I don't know.

The PowerCLI DEV Team must have had their reasons, or perhaps it is something historical.

But you can do this

$esx = Get-VMHost -Name MyEsx

$esx.ExtensionData.Destroy_Task()

The methods with _Task at the end, launch the action and then return.

They do not wait for the end of the requested action.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mark_chuman
Hot Shot
Hot Shot

Thanks Luc.  Any idea how to get this into a foreach loop?

$CSVhosts = Import-Csv .\$OldvCenters\$Cluster\VMHost.csv

$esx = Get-VMHost -Name $CSVhosts.name

foreach ($vmshost in $CSVhosts) {$esx.ExtenionData.Destroy_Task()}

Results in:

Action to take for this exception:

You cannot call a method on a null-valued expression.

[C] Continue  [I] Silently Continue  [B] Break  [S] Suspend  [?] Help (default is "C"): C

what i was using before.

$CSVhosts = Import-Csv .\$OldvCenters\$Cluster\VMHost.csv

foreach ($vmhost in $CSVhosts) {Remove-VMHost -VMHost $vmhost.name -confirm:$false}

I'm sure I'm mutilating this one.

Reply
0 Kudos
LucD
Leadership
Leadership

Try like this

Import-Csv .\$OldvCenters\$Cluster\VMHost.csv | %{

   $esx = Get-VMHost -Name $_.name

   $esx.ExtenionData.Destroy_Task()

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
mark_chuman
Hot Shot
Hot Shot

Ok, it's official.  I've started including "lucd" in google searches for scripts instead of "powercli".  Many thanks for the help over the years!!!

Reply
0 Kudos
mark_chuman
Hot Shot
Hot Shot

Sorry to bring up a dead post, but can you try this Luc and see if you get the same results?

You cannot call a method on a null-valued expression.

[C] Continue  [I] Silently Continue  [B] Break  [S] Suspend  [?] Help (default is "C"): C

Reply
0 Kudos
LucD
Leadership
Leadership

It seems that $esx doesn't hold a VMhost object.

Are there any blank lines in the CSV perhaps (an extra <CR><LF> at the end of file) ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mark_chuman
Hot Shot
Hot Shot

Interesting.  The csv contents look good and the write-host is spitting out the correct name.

$SourcevCenter = "vcenter name"

$Cluster = "cluster name"

Import-Csv .\$SourcevCenter\$Cluster\VMHost.csv | %{

   $esx = Get-VMHost -Name $_.name

   Write-Host $esx

   $esx.ExtenionData.Destroy_Task()

}

Additional notes:

When I intentionally input an incorrect server name into the csv I receive and additional error regarding the host not being found, but this is coming from the "Get-VMHost" when setting the $esx variable.

Get-VMHost : 06/24/2014 8:49:55 AM    Get-VMHost        VMHost with name 'incorrect server name' was not found using the specified filter(s).

At C:\Scripts\Working\Evaluating\loop.ps1:6 char:11

+    $esx = Get-VMHost -Name $_.name

+           ~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (:) [Get-VMHost], VimException

    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

Reply
0 Kudos
LucD
Leadership
Leadership

Could it be that you have a powered down or "ghost" ESXi server in your environment ?

Does

Import-Csv .\$SourcevCenter\$Cluster\VMHost.csv | %{

     Get-VMHost -Name $_.Name | Select Name, ConnectionState,PowerState

}

give any additional clues ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mark_chuman
Hot Shot
Hot Shot

The computers must laugh at us humans Smiley Happy.

Extension (with an S).

Reply
0 Kudos