9

The following PowerShell code to publish an array of pages fails, because the arguments or parameters are in the wrong format.

Example code:

$client.publish($toPublish, $publishInstruction, @($targetId), $null, $readOptions);

$toPublish is an array with tcm id's, and $toPublish.getType() return Object[].

$publishInstruction is a reference to the PublishInstructionData class and $publishInstruction.getType() returns the same class.

$targetId is a string with the target type.

$readOptions is a reference to the ReadOptions class.

The publishing priority is now set to null, but also set to "Publish".

PowerShell returns error message:

Cannot find an overload for "Publish" and the argument count: "5".
$client.publish <<<< ($toPublish, $publishInstruction, @($targetId), $null, $readOptions);
+ CategoryInfo          : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest

I guess that the enum for the priority is the culprit, since the other params are of the correct type.

So what the correct syntax for publishing an array of pages using the PowerShell language? (haven't found no working example using Google).

2011 SP1 API Reference Guide.CHM:

IEnumerable<PublishTransactionData> Publish(
    IEnumerable<string> ids,
    PublishInstructionData publishInstruction,
    IEnumerable<string> targets,
    Nullable<PublishPriority> priority,
    ReadOptions readOptions
)
  • The SDL Tridion 2011 SP1 API Reference Guide (CHM) documents the signature: IEnumerable<PublishTransactionData> Publish( IEnumerable<string> ids, PublishInstructionData publishInstruction, IEnumerable<string> targets, Nullable<PublishPriority> priority, ReadOptions readOptions ) – user348 Jun 20 '13 at 8:30
8

The signature of Publish method in Powershell is like this:

Publish(string[] ids, PublishInstructionData publishInstruction, string[] targets, Nullable`1 priority, boolean prioritySpecified, ReadOptions readOptions)

So you are missing 1 parameter. Try:

$client.publish($toPublish, $publishInstruction, @($targetId), $null, $false, $readOptions);
  • thanks that works, so there are 6 parameters necessary, the 2011 API Reference CHM available from SDLTridionWorld > Documentation show only five parameters. – user348 Jun 20 '13 at 8:32
  • 1
    CHM is describing parameters you get when using precompiled CoreService DLL, but you are using self generated service reference. Tridion can not be responsible for references generated by different clients. BTW, if it works it would be nice if you could accept my answer – Andrey Marchuk Jun 20 '13 at 11:35
  • sorry, your solution does work, and I do see why, because of the Nullable type, in PowerShell you need code to tell if it is nullable or not, and if so, the value. – user348 Jun 20 '13 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy