# Problems trying to register Elasticsearch.NET/NEST in PowerShell

**URL:** <https://discuss.elastic.co/t/problems-trying-to-register-elasticsearch-net-nest-in-powershell/232215>\
**Category:** Elasticsearch\
**Created:** [May 12, 2020, 11:25am UTC](https://discuss.elastic.co/t/problems-trying-to-register-elasticsearch-net-nest-in-powershell/232215 "2020-05-12T11:25:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![syPY45Xb5n7S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sypy45xb5n7s/32/68147_2.png) [@syPY45Xb5n7S](https://discuss.elastic.co/u/syPY45Xb5n7S)\
**Post date:** [May 12, 2020, 11:25am UTC](https://discuss.elastic.co/t/problems-trying-to-register-elasticsearch-net-nest-in-powershell/232215/1 "2020-05-12T11:25:27Z")

</div>

I've been looking into using [elasticsearch.net](http://elasticsearch.net) and nest via powershell instead of re-inventing the wheel with all the different type of web-requests. As dotnet DLLs, it should be possible to use them with PowerShell via **Add-Type** and/or [System.Reflection.Assembly]Load methods.

I've loaded the dependencies of system.buffers & System.Diagnostics.DiagnosticSource into memory, but still receive an error message:

Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.3.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

Has anyone been able to successfully implement use of these clients with PowerShell?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [May 13, 2020, 3:30am UTC](https://discuss.elastic.co/t/problems-trying-to-register-elasticsearch-net-nest-in-powershell/232215/2 "2020-05-13T03:30:04Z")

</div>

Never tried to do this, but there may be some pointers in the [elastico](https://github.com/gigi81/elastico) PowerShell module codebase, which provides cmdlets for operations using the .NET client.

You may also be interested in checking out [Elastic.Console](https://github.com/elastic/powershell/tree/master/Elastic.Console) which provides a few cmdlets for working with Elasticsearch from PowerShell 3.0+ and Core.

---

<div class="post-metadata">

**Author:** ![syPY45Xb5n7S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sypy45xb5n7s/32/68147_2.png) [@syPY45Xb5n7S](https://discuss.elastic.co/u/syPY45Xb5n7S)\
**Post date:** [May 13, 2020, 4:29am UTC](https://discuss.elastic.co/t/problems-trying-to-register-elasticsearch-net-nest-in-powershell/232215/3 "2020-05-13T04:29:11Z")

</div>

Thanks Russ,

I'd taken a look at those previously, but unfortunately one of them is just wrapping the web requests, and the other actually using C# files in the module. .

Timing is mad actually, as I've just found something that i still can't understand, which is that I'm able to successfully load the [Elasticsearch.NET](http://Elasticsearch.NET) and NEST types if I launch them from PowerShell 7 as opposed to Windows PowerShell. That's despite the fact that I specifically use the full framework dlls.

It might be that somehow the [Elasticsearch.NET](http://Elasticsearch.NET) full framework DLL is targeting the net core diagnosticsource one somehow, but really not sure, PowerShell is more my thing than C#.

I'll see if the methods and properties work. If I need to introduce PowerShell 7 LTS to my work to make it happen, then I'll see what I can do.

Will update with findings. 🙂

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [May 13, 2020, 5:00am UTC](https://discuss.elastic.co/t/problems-trying-to-register-elasticsearch-net-nest-in-powershell/232215/4 "2020-05-13T05:00:43Z")

</div>

> [@syPY45Xb5n7S](#):
>
> It might be that somehow the [Elasticsearch.NET](http://Elasticsearch.NET) full framework DLL is targeting the net core diagnosticsource one somehow, but really not sure, PowerShell is more my thing than C#.

Windows PowerShell would need to use the full framework TFM of the client, which is .NET Framework 4.6.1 for later releases such as [NEST and Elasticsearch.Net 7.6.2](https://www.nuget.org/packages/Elasticsearch.Net/). Under dependencies for `.NETFramework 4.6.1`, it's using `System.Diagnostics.DiagnosticSource >= 4.5.1`, which will be `.NETFramework 4.6` version of [`System.Diagnostics.DiagnosticSource` nuget package](https://www.nuget.org/packages/System.Diagnostics.DiagnosticSource/), version 4.5.1 or greater. From there, you'll need to go through its dependencies, etc.

I'm curious to understand why something like `Elastic.Console` doesn't fit your needs? You'd be able to transform any json responses with `jq`, add `Newtonsoft.Json` and use [Json.NET](http://Json.NET)'s linq types, or use PowerShell's `ConvertFrom-Json` (though it's a little clunky).

---

<div class="post-metadata">

**Author:** ![syPY45Xb5n7S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sypy45xb5n7s/32/68147_2.png) [@syPY45Xb5n7S](https://discuss.elastic.co/u/syPY45Xb5n7S)\
**Post date:** [May 13, 2020, 5:32am UTC](https://discuss.elastic.co/t/problems-trying-to-register-elasticsearch-net-nest-in-powershell/232215/5 "2020-05-13T05:32:12Z")

</div>

Yeah, I'd had a look at the DLLs with Dotpeek and downloaded versions for the dependencies that matched the requirements, but didn't have any joy.

I've had a look at elastic.console, but for the initial stage I've already written functions which target the main api functions via invoke-restmethod, do stuff like coverting pscustomobjects to json before attaching it to the body. It'd be handy no doubt if I hadn't already got to that stage.

But for next stage, the [ElasticSeach.NET](http://ElasticSeach.NET) & NEST would mainly offer me a way with a client to not have to re-invent the wheel by being able to use their methods, functions en all in my own PS classes and only requiring to register a few dlls.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 10, 2020, 5:36am UTC](https://discuss.elastic.co/t/problems-trying-to-register-elasticsearch-net-nest-in-powershell/232215/6 "2020-06-10T05:36:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
