The proper way to call Remove-ProvVM using the results of Get-ProvVM is to use the comma
operator to force the result of Get-ProvVM to be an array. The commands for this will use the ,()
syntax.
For example, if there is a provisioning scheme called "provscheme" and all the virtual
machines need to be removed from that provisioning scheme, the proper way to do it would be:
,(Get-ProvVM -ProvisioningSchemeName provscheme) | Remove-ProvVM provscheme
By piping the PowerShell cmdlets together using the ,() syntax, Remove-ProvVM will be called one
time, and the entire list of VMs returned from the Get-ProvVM call will be passed as a parameter to
that one call. Remove-ProvVM will then iterate through the list to remove each virtual machine as
expected.
The same cmdlets called without the ,() syntax will result in a separate Remove-ProvVM call for
each virtual machine in the provisioning scheme which will lead to the error that the provisioning
scheme already has another task running.
Problem Cause
This is a symptom of how PowerShell works. With incorrect syntax, calling Get-ProvVM and piping
the results to Remove-ProvVM will result in one separate Remove-ProvVM call for each VM returned
by Get-ProvVM, and may result in the error that the provisioning scheme has another task running.