I'm a developer at a university in Chicago supporting Ellucian/Datatal Colleague on Unidata 7.2. 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. 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.
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. In order to do that I put together a Powershell script to take a flat file and update AD. However, the beauty of Powershell scripting is that you can work natively with .Net framework objects. 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.
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. 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.
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. 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.
Thank you for asking this question.
You can call very easily U2 Toolkit for .NET (U2NETDK) from Windows PowerShell.
See the enclosed screen shot.
I did the following:
Install U2 Toolkit for .NET
Refer the installed .NET U2NETDK assembly
Create Connection Object
Create Command Object
Open Connection
Execute ADO.NET Command ( SELECT FIRST_NAME, SURNAME FROM MEMBERS)
Fetch Data. Write data on the PowerShell
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.
I hope this example will help other U2 .NET Users too.
See this example:
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.
For Native Access ( Uniobjects API), you do not need UODOTNET.DLL.
We have embedded Uniobjects API in U2NETDK.
So you will refer U2.Data.Client and U2.Data.Client.UO namespaces. 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()
Related
I need a PowerShell (v2) script to read or copy files from a SharePoint library resident on a remote SharePoint server. The twist is, I need to filter on the last modified date of the file(s). Also, the server running the script does not have SharePoint installed.
Here's what I've tried:
Get-ChildItem using the UNC path of the SP file with LastWriteTime filter. I encountered latency issues with this. It runs fine if I've recently opened the document library in the web. But when scheduled to run on its own, the read consistently fails (cannot find file).
Copying the files with the script below. Problem is that the modified date is lost when it's copied to the target machine. The date added/modified is now the copy date.
$target = "http://myspweb.com/myfile.xlsx"
$dest = "D:\library\newfile.xlsx"
$wc = New-Object System.Net.WebClient
$wc.UseDefaultCredentials = $true
$wc.DownloadFile($target, $dest)
Using the Get-SPWeb command. Allegedly, this exposes properties of the files, including last modified date, but seems to require that the server running the script have SharePoint installed (Add-PSSnapin Microsoft.Sharepoint.Powershell gives a "not installed on this machine" error.) A full SharePoint installation isn't really an option -- nor is remoting. Some installation of SP tools might be an option, but I can't figure out what would be required.
Any other ways to approach this?
What you can't do (server-side object model)
The Get-SPWeb cmdlet can only be used from one of the web front end servers that are actually running SharePoint as part of your SharePoint farm, so if you don't have access to log in to the server, that option is right out.
What you can do (web services)
Alternatively, SharePoint exposes web services that you can use to access SharePoint data (including column data) from a remote server.
The available web services vary depending on which version of SharePoint you are using.
The Lists Web Service
The SharePoint 2010/2013 Lists.asmx web service can be accessed if you're willing to compose your own SOAP calls. You can refer to this answer for an example that uses Powershell. Refer to the official documentation here.
You can either format your query so that it only returns results with a certain modified date (using CAML query syntax), or you can return all the results and process them in Powershell to select the ones you care about.
The REST API
SharePoint 2013 also has a REST-based web service you can use. (Technically, SharePoint 2010 does as well, but it's a bit half-baked.) Here's an example using Powershell and the REST API: https://gallery.technet.microsoft.com/office/How-to-Get-all-the-Lists-a0af6259
Using Powershell, how can I find out if my server has NUMA enabled and how many CPUs are assigned to each NUMA node?
Update:
I found out here that the microsoft.sqlserver.management.smo.server object object has an affinityinfo field. However, that field doesn't exist in my server object in Powershell when I create it (SQL Server 2005 on Windows XP).
Update:
It appears that the affinityinfo field only exists in SQL Server 2008 R2 and later.
There are APIs available that will get you this information but they are unmanaged which means they are not easily callable from PowerShell (.NET). In order to call these directly you have to use the Add-Type cmdlet to compile C# code into an in-memory assembly which you would then instantiate or invoke a static method from. I have an example of what this looks like on my blog.
Writing the C# is the tricky part because there is a lot of unfriendly looking code associated with it, check out this example. If you are familiar with C#, you might be able to adapt this to what you want. If not Mark has a tool called Coreinfo that looks like it will get you the information you are looking for. It actually calls the same unmangaged API that the linked p/invoke code does (GetLogicalProcessorInformation). You can just call this from PowerShell and process its STDOUT.
I don't think that native OS APIs in Windows 7 and Windows Server 2008 R2 for working with more than 64 logical processors are available in .NET, you can have a look to .NET Support for More Than 64 Processors. This guy use to write a .NET wrapper for OS APIs, you perhaps use that in PowerShell.
ASP.NET Membership is just great as there are a ton of functionality right there to be used, and we don't need to change nothing at all.
We can even create our own Provider based on Membership database, and that give us infinite possibilities, like as I don't like the Question/Answer I just use an email that is sent with a reset link.
But this is all done with SQLEXPRESS .mdf file and I wanted to use my own Database for this so I can use SQL Server Enterprise as we have in the Office and not the Express Edition.
How can I easily use the ASP.NET Membership tables in my own Database?
I rememebered some years ago that we needed to use aspnet_reg (something) to create the correct tables, but I can't find that info anymore.
I also tried to use other Membership Providers, namely Altairis.Web.Security from CodePlex and saw the Chris Pels Video on creating a new Membership Provider
On Altairis solution, the Model is not complete and lack several points such as Several Applications as it's made to be used with only one, and Chris Pels contains to much Store Procedures that I need to create by hand.
I'm for given Chris code a go but I just wanted to know if there would be available something easier.
All this is to be integrated in ASP.NET MVC 2 Web Application.
Thanks
You have 3 options:
Do it by running aspnet_regsql.exe: Just open "Start Menu>All Programs>Microsoft Visual Studio 2010>Visual Studio Tools>Visual Studio Command Prompt(2010)" and then type aspnet_regsql. A wizard appears and let you select your desired database.
Do it via API: Use System.Web.Management.SqlServices class and its Install and Uninstall methods. This will programmatically install/uninstall database artifacts.
Do it manually: Go to C:\Windows\Microsoft.NET\Framework\v4.0.30319 or something like. You will find 9 .sql files that begins with Install and 9 .sql files that begins with uninstall. You can run them manually in your database to create needed tables/store procedures/etc. But consider changing database name in sql scripts. Default db name is aspnetdb.
It's aspnet_regsql
Under the following path:
C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql
You need to open up the Visual Studio Command Prompt, navigate to C:\WINDOWS\Microsoft.NET\Framework\\aspnet_regsql.exe . Some example are located in the MSDN documentation.
Example: aspnet_regsql.exe -E -S localhost -A mr - installs the database elements for membership and role management on the local computer running SQL Server using Windows authentication.
I've created an app that connects remotely to SQL Server 2008. SQL connections work and all traditional oCommand.ExecuteNonQuery(), work great!
But my SMO class using server.ConnectionContext.ExecuteNonQuery(scriptfile);
ERROR: missing batch parsing.dll .
I can't install these independent utils on a client machines, and then take them all off when done:
as suggested by: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=228de03f-3b5a-428a-923f-58a033d316e1
Since my bulk-inserts are large memory hogs containing complete tables, I wrote the tables to a temptable.sql files and used SQLCMD Util and later switch too SMO and I have the same problem. Neither of these can be leveraged on the client's PCs . Any suggestion? thanks :-)
Well, two things:
if you want to use SMO in your apps, you need to make sure the SMO components are installed on the client machines. You can grab the SMO binaries from Microsoft and you can ship and install them with your app - but that's the only way you'll get those onto the client's computer legally
if you can't do that, how about checking out the SqlBulkCopy class. This is designed specifically for bulk inserting large volumes of data, it's part of ADO.NET 2.0 - no extra installs. There's a whole section in the MSDN library on SQL Server Bulk Operations - check it out!
Is there such a thing as a shell-based command-line client for Microsoft's Jet database engine?
Something similar to SQLite 3.x (sqlite3.exe) for SQLite.
Will PowerShell be suitable? Fellow MVP Richard Siddaway has started a very interesting series of blog postings on using PowerShell and Access. You can ignore the Office 2010 tag on his blog postings. Also note that I know nothing about PowerShell.
This may suit:
Cscript.exe is a command-line version
of the Windows Script Host that
provides command-line options for
setting script properties.
With Cscript.exe, you can run scripts
by typing the name of a script file at
the command prompt. Like Microsoft
Internet Explorer, Windows Script Host
serves as a controller of Windows
Script compliant scripting engines,
but Windows Script Host has very low
memory requirements. Windows Script
Host is ideal for both interactive and
non-interactive scripting needs, such
as logon scripting and administrative
scripting.
Windows Script Host supports scripts
written in VBScript or JScript.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/wsh_runfromcommandprompt.mspx?mfr=true
Something like osql with the right data provider? http://msdn.microsoft.com/en-us/library/aa214012(SQL.80).aspx
Entering the conversation here 10 years after the original question, but I've played with a couple of tools that should work:
YouAccess (http://youaccess.sourceforge.net): "YouAccess is a free (donationware) lifesaver console µapplication intended for SQL management of Microsoft® Access™ databases from command line, including creating them."
JetSQLConsole (https://sourceforge.net/projects/jetsqlconsole): "A command line/console interface for Microsoft Access databases, very similar to the MySQL client application."