Error: Provisioning Scheme already has another task running in PowerShell

Error: Provisioning Scheme already has another task running in PowerShell

book

Article ID: CTX584637

calendar_today

Updated On:

Description

NOTE: This article contains information about removing virtual machines in bulk directly
from PowerShell

Removing multiple virtual machines at a time can be done using Remove-ProvVM but if not done
with the correct syntax, it will generate errors indicating that the provisioning scheme already has
another task running.

 

Environment

The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.

Resolution

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.

Additional Information

This PowerShell help page describes the comma operator.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.4#comma-operator-