Background: During process automation we face multiple challenges, multiple technologies, multiple constraints, limited tools, limited knowledge and off course very limited budget :).

Given if I want to automated my task, because of the above constrains we struggle a lot. One of the most dreaded of such areas I have seen is AS400. Although its share has been decreasing, but it just wont go away.

We were tasked with to automate such items to do some activities collect some data from i series systems and report back. So we started looking for out of the box opensource solutions (limited budget i told you).

We have seen multiple ways of doing that , Multiple off the shelf tools on the market(here), IBM i- series supports macros itself (here). We explored macros and they have some tremendous capability, that will be a blog for some other time though. Also another open source AS400 tool that supports almost everything that we need (here).

But all those did not support 3 basic things , It should be cheap, I should be able to login by itself and it should work in the background as a job, while I work(watch cat videos) on my system

So with the background of the way lets get on with it. We will be needing 1 full power-shell ISE, and x3270 downloaded fresh from here. Take a portable version so that its good for your PC health. We will also be using a new module for powershell Await (here). We are all done with ingredients. If you need you can open a AS400 public account here

To give a bit of detail , Await module allows us to run interactive commandlines via powershell. x3270 allows for AS400 automation. Let me give you the code, It will be self explanatory

#Import-Module await # in case needed #get-command -Module await  # get await commands Start-AwaitSession   # Start automated session Start-Sleep 1   Send-AwaitCommand "& 'D:\path\to\ws3270.exe' -model 3278-2 -port 23 pub400.com"Start-Sleep 1#Wait-AwaitResponse User  # wait for "user" in the responseStart-Sleep 1Send-AwaitCommand 'query(Cursor)' # query(Cursor) is a x3270 command details hereStart-Sleep 1Wait-AwaitResponse 'ok'Start-Sleep 1Send-AwaitCommand 'string("AS400user")'Start-Sleep 1Wait-AwaitResponse 'ok'Start-Sleep 1Send-AwaitCommand 'movecursor(6,25)'Start-Sleep 1Wait-AwaitResponse 'ok'Start-Sleep 1Send-AwaitCommand 'string("AS400Password")'Start-Sleep 1Wait-AwaitResponse 'ok'Start-Sleep 1Send-AwaitCommand 'enter()'Start-Sleep 1Wait-AwaitResponse 'ok'Start-Sleep 1Send-AwaitCommand 'ascii()'Start-Sleep 5#Wait-AwaitResponse 'IBM i Main Menu'Receive-AwaitResponseStart-Sleep 1Stop-AwaitSession

I have given you a basic script to get started make sure that we have gone through the scripting page for x3270 here. If you need anything I will be avalible here for your help.

Thats all folks until next time then

--

--

--

## More from Ibrezm

Love podcasts or audiobooks? Learn on the go with our new app.