Running Powershell script through Ansible is not producing output file

877 views Asked by At

I have a PowerShell script that runs another script from local server fine when executed locally and produces results in a standard text file.

However, when I run the same script through Ansible Runbook, no result is produced

The PowerShell script is-

# RunCis.ps1
# Import DBA functions 
# Construct local instance name and execute Getter script, format output and redirect to 
# a text file on the local server
  .\ImportAllLmeSqlDbaFunctions.ps1

$inst = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
$instance = "$env:COMPUTERNAME\$inst"

Get-CISAdHocDistQueries -Instances $instance| format-table -AutoSize > c:\cis\output.txt 

The Ansible Runbook is-

---


# Below will create directory if not existing

- name: Copy Powershell scripts to remote server 
  copy:
    src: cis
    dest: c:\
- name: Run CIS powershell script on the remote server
  win_shell: C:\cis\RunCis.ps1 

Your help is much appreciated.

0

There are 0 answers