9

I am trying Andrey's way to create a Core Service client in Powershell and having this issue.

I recreate the example on my Windows 7 machine. So far I learned I have run PowerShell ISE as root and run the Set-ExecutionPolicy RemoteSigned to allow unsigned PowerShell stuff.

When I run the this

$config_path = "D:\SDL Tridion\Core Service PowerShell\Andrey\2011SP1\Tridion.ContentManager.CoreService.Client.dll.config"
copy "$config_path" "$pshome\powershell.exe.config" -Force

[appdomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "$pshome\powershell.exe.config")
Add-Type -Path "D:\SDL Tridion\Core Service PowerShell\Andrey\2011SP1\Tridion.ContentManager.CoreService.Client.dll"

$client = New-Object Tridion.ContentManager.CoreService.Client.SessionAwareCoreServiceClient("wsHttp_2011")

I get this error.

New-Object : Exception calling ".ctor" with "1" argument(s): "Could not find endpoint element with name 'wsHttp_2011' and contract 'Tridion.ContentManager.CoreService.Client.ISessionAwareCoreSe
rvice' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be f
ound in the client element."
At D:\SDL Tridion\Tridion 2013 release\Source code\Core Service PowerShell\Andrey\example.ps1:7 char:25
+     $client = New-Object <<<<  Tridion.ContentManager.CoreService.Client.SessionAwareCoreServiceClient("wsHttp_2011")
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

What is missing here? Do I need any other resources aside Tridion.ContentManager.CoreService.Client.dll.config and Tridion.ContentManager.CoreService.Client.dll?

  • +1 as a good question with context, steps taken, example code, and error message. We'll see if Andrey or Dominic Cronin will reply first. ;-) – Alvin Reyes Mar 7 '13 at 23:58
8

The thing is that powershell.config should be in the folder before Powershell is started. So it should work on second run. Also, try running your script directly and not from ISE. What is also worth checking is which Powershell you are running. Is it 32 or 64 bit? You can use procmon to see if config is actually being loaded and if so, from which location.

I personally find this way of connecting: http://amarchuk.blogspot.nl/2011/10/accessing-tridion-coreservice-with.html a bit more convinent.

| improve this answer | |
  • Running the script directly worked! I don't understand why since the same does not work in ISE, even if the configuration file is in the location before starting ISE or running the script a second time. I'm using the 64 bit PowerShell. – Jan H Mar 8 '13 at 13:40
  • I think ISE is not really running powershell.exe, hence can't see config. I recommend using PowerGui editor. It can do the trick with config. Also, as it worked you can accept my answer :) – Andrey Marchuk Mar 8 '13 at 15:19
  • Does the script rely on something that you set up in your $profile? The shell and the ISE have distinct $profiles. – Dominic Cronin Mar 10 '13 at 14:22
7

The first thing I'd check is what the error message says, so try these steps:

  1. Evaluate $pshome\powershell.exe.config in your powershell
  2. Check that there is a file there
  3. In the file, check that it is a valid configuration file, and that it describes an endpoint called wsHttp_2011 that matches the rest of the details specified.

Do you already know that the configuration file you are trying to wire up actually works? For example, from a C# console app?

Some people think it's easier to wire up the configuration from code rather than a config file when using Powershell. Peter Kjaer's Tridion powershell module is useful for this, and of course, I'm also going to point you at my own write-up on the subject.

| improve this answer | |
  • Thanks. I read the your post and Peter Kjaer's project but decided to start with Andrey's solution. I will try the other ones too to understand the matter fully. I am in a bit of a PowerShell learning curve here. – Jan H Mar 8 '13 at 12:17
  • What were your results from checking those things? – Dominic Cronin Mar 8 '13 at 13:10
  • 1. $pshome\powershell.exe.config did evaluate 2. the file was there 3. it was a valid config 4. I did not try the config file with a C# console app, but found the solution in PowerShell instead. 5. configuration from code is my next step. – Jan H Mar 8 '13 at 22:28
2

Thanks to user978511 and Dominic's answers I got the example to work. I found the following:

  • In order to set the "$pshome\powershell.exe.config" you need admin rights, so PowerShell had to be run as Administrator.
  • After running the script, the PowerShell console has to be closed and started again in order to pick up the config in "$pshome\powershell.exe.config".
  • This only worked in the "normal" PowerShell console and not in ISE.

After having the "$pshome\powershell.exe.config" in place, I could disable the line of code with the config copy and run the script as a normal user.

I think the config in copy "$pshome\powershell.exe.config" is not very practical. So it would make more sense to have the configuration in code like you would do in a C# project and like Dominic suggested.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.