# Custom Ohai plugin using powershell script

**URL:** <https://discourse.chef.io/t/custom-ohai-plugin-using-powershell-script/21677>\
**Category:** Chef InSpec\
**Created:** [December 19, 2022, 9:32pm UTC](https://discourse.chef.io/t/custom-ohai-plugin-using-powershell-script/21677 "2022-12-19T21:32:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JKadoo](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@JKadoo](https://discourse.chef.io/u/JKadoo)\
**Post date:** [December 19, 2022, 9:32pm UTC](https://discourse.chef.io/t/custom-ohai-plugin-using-powershell-script/21677/1 "2022-12-19T21:32:01Z")

</div>

Hi I hope someone can point me in the right direction. I have a custom ohai plugin that I am using to gather some information about our windows servers. I have been directed to have ohai use a powershell script to gather the information. I am struggling to figure out how to get the local powershell script to return the value back to ohai for reporting purposes

Here is what I have so far:

Ohai.plugin(:HyperVServer) do  
require 'json'  
provides 'hyperv\_networks'

```
collect_data do
  powershell_script 'Get HyperV Networks' do
  hypervnetworks = code '. c:/scripts/Get-HyperVNetworks.ps1 | ConvertTo-Json'
  end   
  hyperv_server[:hypervnetworks] = hypervnetworks
end

```

end

but I don't think this will work. Thoughts?

---

<div class="post-metadata">

**Author:** ![Stromweld](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/stromweld/32/3416_2.png) [@Stromweld](https://discourse.chef.io/u/Stromweld)\
**Post date:** [December 19, 2022, 10:24pm UTC](https://discourse.chef.io/t/custom-ohai-plugin-using-powershell-script/21677/2 "2022-12-19T22:24:49Z")

</div>

ohai doesn't use the chef resources you'd have to include them by class to make them available in your ohai plugin. Here's a couple of docs on how to write ohai plugin and a powershell example. [Writing Ohai Custom Plugins](https://docs.chef.io/ohai_custom/)  
[ohai/powershell.rb at de7b4f4349c767120f223b0569687187082ad73c · chef/ohai · GitHub](https://github.com/chef/ohai/blob/de7b4f4349c767120f223b0569687187082ad73c/lib/ohai/plugins/powershell.rb)

---

<div class="post-metadata">

**Author:** ![JKadoo](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@JKadoo](https://discourse.chef.io/u/JKadoo)\
**Post date:** [December 20, 2022, 8:59pm UTC](https://discourse.chef.io/t/custom-ohai-plugin-using-powershell-script/21677/3 "2022-12-20T20:59:19Z")

</div>

Thank you so much for this information. I really appreciate it. This makes sense. So in line with this is it possible for ohai to read a json file on the local system?

---

<div class="post-metadata">

**Author:** ![Stromweld](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/stromweld/32/3416_2.png) [@Stromweld](https://discourse.chef.io/u/Stromweld)\
**Post date:** [December 20, 2022, 9:57pm UTC](https://discourse.chef.io/t/custom-ohai-plugin-using-powershell-script/21677/4 "2022-12-20T21:57:35Z")

</div>

yes very common to parse a json file either from local filesystem or from an api call return from other systems.
