I need to delete a hell lot of records using a web-service. The module Microsoft.Xrm.Data.Powershell provides several cmdlets to get this job done.
The following script should be executed by the different jobs:
$packageCmd = {
param($jobName, $crmConnection, $package)
# Xrm is not a module that is system-wide loaded
Import-Module Microsoft.Xrm.Data.Powershell
$counter = 0
write $jobName
foreach($record in $package) {
Remove-CrmRecord -conn $crmConnection -EntityLogicalName 'foobar' -Id $record.foobarid
$counter++
}
}
This is the code I use to execute my jobs:
foreach($p in $packages) {
$jobname = $jobName = ('Del_Data_Pak_{0}' -f $packageNumber)
Start-job -Name $jobname -ScriptBlock $packageCmd -ArgumentList $jobName, $crmConnection, $p
$packageNumber++
}
When I execute my code the following error message is thrown inside the jobs:
Der aktuelle Windows PowerShell-Host ist: "ServerRemoteHost" (Version 1.0.0.0). Zum Ausführen
des Moduls "C:\Users\foobar\Documents\WindowsPowerShell\Modules\Microsoft.Xrm.Data.Powershell\Micro
soft.Xrm.Data.Powershell.psd1" ist mindestens Version 4.0 des Windows PowerShell-Hosts
erforderlich.
+ CategoryInfo : ResourceUnavailable: (C:\Users\foobar\Do...Powershell.psd1:String) [
Import-Module], InvalidOperationException
+ FullyQualifiedErrorId : Modules_InsufficientPowerShellHostVersion,Microsoft.PowerShell.Co
mmands.ImportModuleCommand
+ PSComputerName : localhost
The error message says that the module "Microsoft.Xrm.Data.Powershell" requires version 4.0 of PowerShell, but that the current host is using version 1.0.
Based on the online documentation for Start-Job can I pass the parameter -PSVersion but only with the values 2.0 or 3.0.
Does this mean that it is simply not possible to execute an job that uses a module that requires PowerShell 4.0 /5.0?
Update 2016-02-04: I commented out the following line in the file "Microsoft.Xrm.Data.PowerShell.psd1"..
# Minimum version of the Windows PowerShell host required by this module
#PowerShellHostVersion = '4.0'
... but now I receive this error inside the jobs:
Die Argumenttransformation für den Parameter "conn" kann nicht verarbeitet werden.
Der Wert "Microsoft.Xrm.Tooling.Connector.CrmServiceClient" vom Typ
"Deserialized.Microsoft.Xrm.Tooling.Connector.CrmServiceClient" kann nicht in den
Typ "Microsoft.Xrm.Tooling.Connector.CrmServiceClient" konvertiert werden.
+ CategoryInfo : InvalidData: (:) [Remove-CrmRecord], ParameterBindin.
..mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-CrmRecord
+ PSComputerName : localhost
I do not understand why I have now "Deserialized.Microsoft.Xrm.Tooling.Connector.CrmServiceClient" and "Microsoft.Xrm.Tooling.Connector.CrmServiceClient"