Hi ToddMote! Thanks for the Feedback. In short, I am sorry to say, parallel is not working for this API. It was never build or designed for that and little bit older than the invention of PowerShell.
Btw you can use foreach -parallel with Windows PS 5.1 - but it must be in a Workflow and here we have some restrictions:
about Foreach-Parallel - PowerShell | Microsoft Learn
You cannot use the WMI 1.0 Method like in this Blog because of this restrictions.
The Microsoft Configuration Manager CmdLets supports PowerShell 7 - but you sense it - not in a workflow parallel Code-Block. The reason you need to import the Module - which is not allowed in a workflow. You can overcome it if you provide in the workflow an InlineScript - but the InlineScript runs in an isolation mode - so the rest of the code cannot use it.
Usually you would use Get/New/Set-CIMInstance. But with this approach you will face two different Issues. As mentioned in the Blog the SMS_MachineVariable-Class is only a Type-Reference, we just want such an Object to use it later for the SMS_MachineSettings-Class for one Instance. But if you use something like that:
$MachineVar = New-CimInstance -ComputerName CM01 -Namespace root\sms\site_fox -ClassName SMS_MachineVariable -Property @{Name="TESTVAR";Value="1234";IsMasked=$false}
It will use the Put() Method and you will have one Instance - where usually none exist, where you will face exceptions with the next runtime.
But let us continue:
$Resource = Get-CimInstance -ComputerName CM01 -Namespace root\sms\site_fox -ClassName SMS_MachineSettings -Filter "ResourceID='16777330'"
Set-CimInstance -InputObject $Resource -Property @{MachineVariables=$MachineVar}
If you call this you face a Cast-Exception. The reason with the CIM-Call you get for this Object is a Type of Microsoft.Management.Infrastructure.CimInstance - but the Property MachineVariables need a Type of Microsoft.Management.Infrastructure.Native.InstanceHandle
I see only two Options for you in PowerShell 7 - you use the Configuration Manager Module but without parallel. Then you do not need to care about the CIM-Instances.
Import-Module ConfigurationManager
SL XYZ:
New-CMDeviceVariable -DeviceName WS01 -VariableName TEST -VariableValue 1234 -IsMask $false
Or use the Administration Service and the Rest-API. But this will also not run in parallel.
Exploring Configuration Manager Automation Fundamentals – Administration Service - Microsoft Community Hub
$CMAdminService = Connect-CMAdminService -CMProviderFQDN CM01.FOXWORKS.INTERNAL
# Add a Variable to the Device
$VarOSType = 'WindowsOS'
$VarOSTypeValue = 'Windows 11'
$uri = 'wmi/SMS_MachineSettings'
$ReqBody= @{
LocaleID = 1033;
ResourceID = $($NewDevice.ResourceID);
SourceSite = 'FOX';
MachineVariables = @(
@{
IsMasked = 'False';
Name = $VarOSType;
Value = $VarOSTypeValue;
}
)
}
$NewVar = Invoke-CMAdminServicePost -odata $CMAdminService -query $uri -body $ReqBody
Not the answer what you hoped - but maybe a workaround for your Code-Project.