# Powershell Ansible modules with Linux

**URL:** <https://forum.ansible.com/t/powershell-ansible-modules-with-linux/3143>\
**Category:** Get Help\
**Tags:** windows, vmware, collections, ee\
**Created:** [January 3, 2024, 7:10pm UTC](https://forum.ansible.com/t/powershell-ansible-modules-with-linux/3143 "2024-01-03T19:10:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MallocArray](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mallocarray/32/1655_2.png) [@MallocArray](https://forum.ansible.com/u/MallocArray)\
**Post date:** [January 3, 2024, 7:10pm UTC](https://forum.ansible.com/t/powershell-ansible-modules-with-linux/3143/1 "2024-01-03T19:10:42Z")

</div>

We have several existing Powershell scripts that we wanted to adapt to use with Ansible. Mostly dealing with VMware and so they don’t specifically need a Windows OS.

We didn’t want to just use the win\_powershell command since it is tricky to securely pass secrets into the scripts, so we adapted several of the scripts into full Ansible modules as Powershell files so we could no\_log the passwords. But this requires us to still run this on a Windows host due to the `#!powershell` at the top of the file.

We would rather install Powershell 7 inside of our Execution Environment along with the powershell modules and still use a .ps1 based Ansible module to run completely inside of the Linux based EE to eliminate the delegate host to send it to Windows.

Is there a standard way to do this at this time? When we last looked a year or so ago there wasn’t a supported way. We found one third party repo that had a modified file to start to allow this, but not much movement on that front.

From this link:  
[https://www.redhat.com/en/topics/automation/learning-ansible-tutorial](https://www.redhat.com/en/topics/automation/learning-ansible-tutorial)

I saw “Ansible modules can be written in any language that can return JSON, such as Ruby, Python, or bash.” but that doesn’t appear to include Powershell even if Powershell is available on the Linux box that is running Ansible, but I’m hoping I’ve missed something.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [January 3, 2024, 7:25pm UTC](https://forum.ansible.com/t/powershell-ansible-modules-with-linux/3143/2 "2024-01-03T19:25:42Z")

</div>

I’ve talked about this recently with [Unable to create a powershell module that forces usage of pwsh/powershell core/powershell 7 · Issue #82432 · ansible/ansible · GitHub](https://github.com/ansible/ansible/issues/82432#issuecomment-1865500160). While that comment focuses on `pwsh.exe` on Windows it also applies to `pwsh` on non-Windows (except the `win_powershell` option).

In short you can use PowerShell modules but you won’t have access to any of the shared module\_utils that the Windows PowerShell modules have access to.

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [October 20, 2024, 11:06am UTC](https://forum.ansible.com/t/powershell-ansible-modules-with-linux/3143/3 "2024-10-20T11:06:40Z")

</div>

Thats not exactly true. One can use the legacy modules and I did a proof of concept with it. I wrote a post to it [here].  
([Ansible - PowerShell on Linux using Legacy modules and helper functions](https://weiyentan.github.io/2021/powerShell-ansible-modules-linux/))
