简体   繁体   English

在Windows Powershell中使用用于.Net / UniObjects的U2工具包?

[英]Using the U2 toolkit for .Net / UniObjects in Windows Powershell?

I'm a developer at a university in Chicago supporting Ellucian/Datatal Colleague on Unidata 7.2. 我是芝加哥一所大学的开发人员,在Unidata 7.2上为Ellucian / Datatal同事提供支持。 We recently converted from Unidata on Unix to Windows Server and had a number of extract cron jobs that had to be converted to the new OS. 最近,我们从Unix上的Unidata转换为Windows Server,并且不得不提取许多cron作业,这些作业必须转换为新的OS。 During that conversion, I was introduced to the MS Windows Powershell Scripting Environment and have been using it to automate a lot of tasks that had been procedurally fragmented where the tasks were split up and executed asynchronously on different machines. 在该转换过程中,我被介绍给了MS Windows Powershell脚本环境,并一直使用它来自动执行许多程序上分散的任务,这些任务在不同的计算机上拆分并异步执行。

We are implementing the Ellucian Portal built on MS Sharepoint, and for that task we need to run a nightly job refreshing MS Active Directory attributes from our HR data. 我们正在实现基于MS Sharepoint的Ellucian Portal,为此,我们需要每晚进行一次工作,以从人力资源数据中刷新MS Active Directory属性。 In order to do that I put together a Powershell script to take a flat file and update AD. 为此,我整理了一个Powershell脚本以获取一个平面文件并更新AD。 However, the beauty of Powershell scripting is that you can work natively with .Net framework objects. 但是,Powershell脚本的优点在于您可以使用.Net框架对象进行本机处理。 I had developed a number of applications and utilities using VB UniObjects over the years and this seems to be a perfect opportunity to leverage the Powershell interface and build the extract step directly into the AD update script so the entire process can be executed as a single integrated application. 多年来,我已经使用VB UniObjects开发了许多应用程序和实用程序,这似乎是利用Powershell界面并将提取步骤直接构建到AD更新脚本中的绝佳机会,因此整个过程可以作为一个集成的程序执行。应用。

I've downloaded and installed the U2 toolkit for .Net from Rocket software but I've run into a snag in that the Powershell reference and instantiation syntax is different than any of the Visual Studio languages. 我已经从Rocket软件下载并安装了适用于.Net的U2工具包,但由于Powershell参考和实例化语法不同于任何Visual Studio语言,因此遇到了一个麻烦。 Though I've been able to make some progress and have been able to establish a U2 ADO connection with the U2.Data.Client namespace, I am still having trouble instantiating the Native UniObjects U2.Data.Client.UO objects properly. 尽管我已经取得了一些进步,并且能够与U2.Data.Client命名空间建立U2 ADO连接,但是仍然无法正确实例化本机UniObjects U2.Data.Client.UO对象。

I'm sure that it just a simple issue with referencing the libraries correctly, but I've never actually worked with the .Net framework before, and I can't seem to find any authoritative examples of using the U2 .Net library in Powershell. 我敢肯定,正确引用库只是一个简单的问题,但是我以前从未真正使用过.Net框架,而且在Powershell中似乎找不到使用U2 .Net库的权威示例。 。 This forum appears to be a great resource and the progress I've made is due to posts I've found here. 这个论坛似乎是一个很好的资源,而我的进步归功于我在这里找到的帖子。 If anyone has any thoughts or expertise in both U2 and Powershell I'd love to hear if you have an opinion on how to make the magic happen. 如果有人对U2和Powershell都有任何想法或专业知识,我很想听听您是否对如何实现魔术产生了看法。

Thank you for asking this question. 感谢您提出这个问题。 You can call very easily U2 Toolkit for .NET (U2NETDK) from Windows PowerShell. 您可以从Windows PowerShell轻松调用用于.NET的U2工具包(U2NETDK)。 See the enclosed screen shot. 请参阅随附的屏幕截图。 I did the following: 我做了以下工作:

  1. Install U2 Toolkit for .NET 为.NET安装U2工具包
  2. Refer the installed .NET U2NETDK assembly 请参考已安装的.NET U2NETDK程序集
  3. Create Connection Object 创建连接对象
  4. Create Command Object 创建命令对象
  5. Open Connection 打开连接
  6. Execute ADO.NET Command ( SELECT FIRST_NAME, SURNAME FROM MEMBERS) 执行ADO.NET命令(SELECT FIRST_NAME,来自成员的SURNAME)
  7. Fetch Data. 获取数据。 Write data on the PowerShell 在PowerShell上写入数据
  8. Close the Connection. 关闭连接。

If you want to use UO.NET capability and you want to use read file, UniCommand, SelectList, then refer U2.Data.Client.UO.UniFile, U2.Data.Client.UO.UniCommand etc. 如果要使用UO.NET功能,并且要使用读取文件UniCommand,SelectList,然后引用U2.Data.Client.UO.UniFile,U2.Data.Client.UO.UniCommand等。

I hope this example will help other U2 .NET Users too. 我希望这个示例也能对其他U2 .NET用户有所帮助。

在此处输入图片说明

See this example: http://blogs.technet.com/b/threekings/archive/2008/07/18/ado-net-in-powershell-update-sql-data-example-sample.aspx 参见以下示例: http : //blogs.technet.com/b/threekings/archive/2008/07/18/ado-net-in-powershell-update-sql-data-example-sample.aspx

Thank you for trying U2NETDK' ADO.NET and windows PowerShell. 感谢您尝试使用U2NETDK的ADO.NET和Windows PowerShell。 For Native Access ( Uniobjects API), you do not need UODOTNET.DLL. 对于本机访问(Uniobjects API),不需要UODOTNET.DLL。 We have embedded Uniobjects API in U2NETDK. 我们在U2NETDK中嵌入了Uniobjects API。 So you will refer U2.Data.Client and U2.Data.Client.UO namespaces. 因此,您将引用U2.Data.Client和U2.Data.Client.UO命名空间。 See below the script and screen shot. 请参见下面的脚本和屏幕截图。

Add-Type -Path "C:\Program Files (x86)\Rocket Software\U2 Toolkit for .NET\U2 Database Provider\bin\.NETFramework\v2.0\U2.Data.Client.dll"

$Connection = New-Object U2.Data.Client.U2Connection

$Connection.ConnectionString = "Database=XDEMO;User ID=administrator;Password=pass;Server=9.72.199.235;Persist Security Info=True;ServerType=universe;AccessMode=Native"

$Connection.Open()

$Session = $Connection.UniSession

$UniSelectList  =$Session.CreateUniSelectList(2);

$UniFile  = $Session.CreateUniFile("PRODUCTS");
$UniSelectList.Select($UniFile);

while (!$UniSelectList.LastRecordRead)
{
$sRecID = $UniSelectList.Next();
write-host $sRecID
}
$Connection.Close()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM