I deployed Ansible through Azure DevOps to manage Windows servers. I wrote a ps1 (PowerShell) about monitoring DHCP status and this file executes well directly on the server, but when I execute it using playboo, I don't get any results and no errors are reported. How do I need to fix it please?
Playbook:
- win_shell: C:\temp\DHCP_Config_Global.ps1 -verb runas
ps1 file:
whoami.exe >> C:\Temp\Result.txt
Get-DhcpServerInDC >> C:\Temp\Result.txt
Get-ADReplicationSiteLink -Filter "Name -eq '#PRIMARY'" >> C:\Temp\Result.txt
Get-DhcpServerv4Scope -ComputerName ABC >> C:\Temp\Result.txt
Get-DhcpServerv4Failover -ComputerName DEF >> C:\Temp\Result.txt
In the end only whoami got results in Result.txt, the rest didn't seem to run successfully and no errors were reported. I tried to use win_command instead of win_shell, but the result is the same.
- win_command: powershell.exe -ExecutionPolicy Bypass -File C:\temp\DHCP_Config_Global.ps1 -verb runas