Ad Widget

Collapse

Scripts - Powershell - Multiple commands in one script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zablab
    Junior Member
    • Jan 2022
    • 28

    #1

    Scripts - Powershell - Multiple commands in one script

    Is it possible to chain two PS Commands together when using Scripts?

    For example the following script does a text replacement in the Zabbix Agent config file:

    Code:
    powershell.exe -Command {((Get-Content -path "C:\Program Files\Zabbix Agent\zabbix_agentd.conf" -Raw) -replace "# Timeout=3", "Timeout=30") | Set-Content -Path "C:\Program Files\Zabbix Agent\zabbix_agentd.conf"}
    But I get the following error:

    'Set-Content' is not recognized as an internal or external command, operable program or batch file'

    So I figure it's an escape or issue piping commands? I've tried a few variations with brackets\parenthesis, but wanted to verify if this is even possible or if it's a syntax issue.


    Thanks in advance,

    *Update*

    Got this working, example below. Hope it helps someone else!

    Code:
    powershell.exe -command "(gc -raw 'C:\Program Files\Zabbix Agent\zabbix_agentd.conf').replace('# Timeout=3', 'Timeout=30') | Set-Content 'C:\Program Files\Zabbix Agent\zabbix_agentd.conf'"
    Last edited by Zablab; 17-08-2022, 19:51.
Working...