Hi,
I need little help to make below script faster. I have csv file "VM_s.csv" like this
Name |
David-DR-01 |
David-DR-02 |
David-DR-03 |
David-DR-04 |
David-DR-05 |
and when I use function "foreach", so this script use VM one by one. Is it possible use a faster solution?
$vmNames = Import-Csv -Path .\VM_s.csv -UseCulture | select -ExpandProperty Name
Get-VM -Name $vmNames
foreach ($vm in $vmNames)
{
Get-VM $vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName "My_PortGroup_Name" -StartConnected:$true -Confirm:$false
}
David
You can use the RunAsync switch on the Set-NetworkAdapter cmdlet.
That way the action will run in the background and your script will immediately continue with the next line.
The problem might be that if you have dependencies on that vNIC to be reconfigured for later in your script, that you might have to verify that all these background tasks are actually finished.
You can use the Get-Task cmdlet for that (in a loop)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use the RunAsync switch on the Set-NetworkAdapter cmdlet.
That way the action will run in the background and your script will immediately continue with the next line.
The problem might be that if you have dependencies on that vNIC to be reconfigured for later in your script, that you might have to verify that all these background tasks are actually finished.
You can use the Get-Task cmdlet for that (in a loop)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It works. Thank you very much.
David