Run PowerShell cmdlets With Ansible for Windows

In this blog post,  I will run simple PowerShell cmdlets on a managed Windows machines with Ansible.

Out of the box, Ansible for Windows has many modules can do many administrative tasks that involve managing user, computer, Active Directory and Group Policy however there is time that you might need to run a simple cmdlet.

Win Shell

Using the win_shell Ansible for Windows module we can run any PowerShell cmdlet on a managed host as you will see in the code below.

The Playbook below, I am running a PowerShell cmdlet that installs Nuget package provider. 

Code

---
- name: "Run PoweShell cmdlets"
  hosts: windows
  tasks:
       - win_shell: Install-PackageProvider -Name NuGet -force

If you need to get started with Ansible and Windows, visit the Manage Windows Machines with Ansible blog series.

 

Processing…
Success! You're on the list.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.