This web site uses Kentico CMS, the content management system for ASP.NET developers.
Community > Blogs > Max-PIT> IBM i5Series and PowerShell > December 2008 > PowerShell executing an i5 command
 

PowerShell executing an i5 command

Part 3 of 3

Now, in this sample we are going to executre an i5 command to clear a table.  This is the Clear Physical Member command "CLRPFM".  In ADO.NET, we are going to use the OLEDbCommand() to  hold the command to be executed.
You have to make sure to use the open/closing double brackets "{{ }}" or it will not work. Then, using the ".ExecuteNonQuery()" to execute the command.  

Again, make sure your i5 Security Officer give you the permission required to execute this command.

Executing an i5 command

## Load GAC
[System.Reflection.Assembly]::LoadWithPartialName("System.Data")
[System.Reflection.Assembly]::LoadWithPartialName("IBM.Data.DB2.iSeries")

## Setup you userID and Password
[string] $i5UID = 'YourName_here';
[string] $i5PWD = 'YourPassword_here';

## Create connection to i5Serie
$i5Conn = New-Object System.Data.OleDb.OleDbConnection("Provider=IBMDA400;Data Source=IBMeServer;User ID=$i5UID;Password=$i5PWD;Initial Catalog=S1042B3A");
$i5Conn.Open();

## Perform a i5 command to clear physical file member
$cmd = New-Object System.Data.OleDb.OleDbCommand("{{CLRPFM SALES/EURSTRMST}}",$I5Conn);
$cmd.ExecuteNonQuery() | Out-Null;
$i5Conn.Close();
 


I you have notice, I'm piping the '$cmd.ExecuteNonQuery()' to a 'Out-Null' cmdlet becuase I don't want the result to returned to the consoie.  Now, during debuggin ypou may want to avoid using this so you can see the numbers of record been affected or a returned value (0 or 1).

As you can see with these three blog entries you can connect, query, and run a command on your i5 System.

Posted: 12/6/2008 6:10:56 PM by Global Administrator | with 3 comments


Comments
22
cyj3Iy pndqfxihhszm, [url=http://guwmebhqjpmo.com/]guwmebhqjpmo[/url], [link=http://cxepdlwyhvvf.com/]cxepdlwyhvvf[/link], http://izodtszadslu.com/
2/22/2009 9:38:07 AM

77
gKL2pj koifdmylamif, [url=http://jdnaxclfyjym.com/]jdnaxclfyjym[/url], [link=http://ajmmornavbaw.com/]ajmmornavbaw[/link], http://qvyrrkuanhxc.com/
3/18/2009 4:31:50 AM

agzbktdat
lA6ywA kxkhzfmbxlig, [url=http://ulzrinstirsv.com/]ulzrinstirsv[/url], [link=http://hilfxuooeluj.com/]hilfxuooeluj[/link], http://loioehoiiqgh.com/
4/2/2009 9:46:55 AM

Title

Due to the fact that I have to also work with our IBM i5Series (aka AS/400), I needed to build a solution push data into the system.  So, using the "IBM iSeries Access for Windows" .NET provider, I was able to connect and use our DB2 databses in our i5 system.

It was hard for me to find information on How-to use the 'IBM iSeries Access to Windows" .NET provider to get my PowerShell script to work. I found one link (that I lost again) and a iSeries .NET presentation (C# code), help me complete these samples.

This blog section will provider with the necessary samples to:
1. Get connected to the i5 System
2. Do a SQL Query to a DB2 table
3. Executing a i5 Command

Please, make sure the your "security Office" provide you with the properly configured user ID and Password.


My favourite websites

Syndication

RSS

Post archive

This web site uses Kentico CMS, the content management system for ASP.NET developers.