Powershell: Find out if NUMA is configured and how many CPUs are assigned to each NUMA node? - powershell

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.

Related

Powershell script to get IIS configuration details

I am looking for fairly generic powerhell cdm allowing me to get the information about IIS - which directory is the log being written to and which fields it is logging.
I need to query circa 400 servers in the environment and check for the differences
We use 2008 r2 with IIS 7
Thanks a lot in advance
Yeah I know IIS has WMI interfaces which are pretty solid. You'll need to look up the classes though.

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. 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()

Script the windows azure command line utilities

There is java based server component responsible for remote management of amazon virtual machines. I need to write an azure adapter for this component.
I thought I would be better off using node.js based command line utils for azure management.
I wanted to know the way to invoke scripts either from c#/java and then process the output so that I could pass the output to the calling server component.
for e.g. An instruction to create a new vm will return the instance id back to the calling method.
Basically I would need to script the logic in to the adapter methods.
Any directions will be of great help.
-Sharath
Depending on the technology you're choosing you have a few options:
Using the System.Management.Automation assembly you can call any PowerShell script in a C#/.NET application
In Java you can call a batch file that runs a PowerShell script (where you would invoke the Azure cmdlets). There's an interesting discussion on the MSDN forum.
And why not use the Service Management API? This is a REST API that makes it possible to call it from .NET, Java, Node, ...

Connect to JMX using PowerShell

I am not a developer so please keep that in mind when reading the following message:
I need to be able to use Windows PowerShell to connect to a JMX RMI agent on a host, is this even possible ?
The example string from the java client I have been given is as below:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:7979/jmxrmi");
The reason for this is that I am doing other work in my PowerShell script and would like to keep it all in one place.
Thanks !
This is an unusual mix of two technologies, but it is possible.
On the off-chance that you are attempting to connect to a JBoss server, the quickest way may be for you to call twiddle, a command tool that will dispatch JMX requests to the target JBoss server and return the results to standard out.
Another way is to implement the Jolokia agent on the target servers. This will allow you to issue JMX requests using REST. Responses will also be returned in REST format which you can process in PowerShell using one of these solutions.
Thirdly, you can also deploy the JMX-WS service on your target servers which will allow you to communicate with the JMX server using web-services. This document provides some VBScript examples of this.
None of the above actually uses the JMXServiceURL syntax you outlined, and I cannot think of a way you could actually cleanly integrate this RMI based protocol into PowerShell, but hopefully one of the above will work for you.
========== UPDATE ==========
There may be a way to use the RMI implementation. Take a look at IKVM. It is a Java Byte Code to .NET compiler. I have successfully compiled JMX/RMI java code into a .Net assembly and used it from C#. I think PowerShell will do the same thing.

SMO missing dll on a clients

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!