To put all together:
the documentation Alexander pointed you to is quite complete and should allow the creation of quite powerful scripts.
I wanted to get you started with something that I created a while back for a similar request:
a Windows command that would A) start our Telnet client to B) connect to a specific server and C) execute a script where we can then enable logging and perform multiple actions as needed..
My script example is nothing else as logging into a default namespace (without username/password, so the typical minimal security setting where you would end up in the USER namespace), enable logging, execute a %SS displa for the list of running processes, pause a few seconds, and exit..
The command line would look as follow:
C:\Temp\>C:\InterSystems\E20162\Bin\CTerm.exe /CONSOLE=CN_IPTCP:127.0.0.1 C:\Temp\testlog.scr
And the content of the testlog.scr script:
;Script to test logfiles
wait for: USER>
send: d ALL^%SS<CR>
wait for: >
send: H 10<CR>
Hopefully this will work for you too and act a useful starting point for your actual needs.