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
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
Hi Lucd,
i have updated the code. i have tried just on vm with runasync however the same result as state running.
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
there is no prompt on the console it just returns it to console after the result.
PS C:> $PortGroup = Get-virtualportgroup -name 'Test'
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
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 .
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
How should I use get-task with assigned $NetworkReg variable for network tasks.
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