shanas322
Contributor
Contributor

powercli Runasync state not sync

I have the below code to map network adapter for 300+ VMs, when runasync its state not complete and always running. please advice.

$NetworkReg = @()

$vms= import-csv vmlist.csv

foreach($vm in $vms)
{
$VMadapters = Get-VM "$vm.name" | Get-NetworkAdapter
$PortGroup = Get-VirtualPortGroup -Name "$vm.portgroup"
$NetworkReg += Set-NetworkAdapter -NetworkAdapter $VMadapter -Portgroup $PortGroup -RunAsync -Confirm:$false
}

$NetworkReg

Name State % Complete Start Time Finish Time
---- ----- ---------- ---------- -----------
ReconfigVM_Task Running 6 03:18:20 PM

 
Moderator moved thread to PowerCLI Discussions.
 
0 Kudos
9 Replies
LucD
Leadership
Leadership

It could be that the cmdlet produced a prompt and is waiting for a reply.
Does this work without the RunAsync?
I can't check because you didn't share all relevant code.


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

0 Kudos
shanas322
Contributor
Contributor

Hi Lucd,

i have updated the code. i have tried just on vm with runasync however the same result as state running.

0 Kudos
LucD
Leadership
Leadership

The suggestion was to run for one without RunAsync, just to check if there were any prompts.


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

0 Kudos
shanas322
Contributor
Contributor

there is no prompt on the console it just returns it to console after the result.  

PS C:> $PortGroup = Get-virtualportgroup -name 'Test'

PS C:> Set-NetworkAdapter -NetworkAdapter 'Network adapter 1' -Portgroup $PortGroup -Confirm:$false
 
 Name type networkname macaddress wakeonlane enabled
 xxxx   xx     xxxxxxxxxxx  xxxxxxxx       xxxxxxxxxxxxxxxxx
 
PS C:>
 
 
0 Kudos
LucD
Leadership
Leadership

Are you checking the Task objects returned when you launched the cmdlet with RunAsync?
Or are you doing a Get-Task  to check the current Status?
The returned Task object does not refresh automatically when it is a Server-Side task


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

0 Kudos
shanas322
Contributor
Contributor

im checking the $NetworkReg which is assigned for runasync task. it return always running state. but the task already completed in VC. Set-NetworkAdapter cant use runasync?

 can you share the example which is working from your side? i just want to runasync for Set-NetworkAdapter task .

0 Kudos
LucD
Leadership
Leadership

The see the actual state of the Task, you will need to use Get-Task
Since this returns the status of all recent tasks, you will have to filter by Name or Id.


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

0 Kudos
shanas322
Contributor
Contributor

How should I use get-task with assigned  $NetworkReg variable for network tasks.

0 Kudos
LucD
Leadership
Leadership

The objects returned, which you have in $networkReg, each has a property named Id.
With Get-Task -ID <task-id> you can retrieve the current status of such a Task.


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

0 Kudos