ForEach vs ForEach-Object in PowerShell

In a current project where I use the PowerShell Management Agent from Søren Granfeldt to import information from a large LDAP catalog I discovered that there are some performance problems if you use PowerShell the incorrect way. One of these things is the use of ForEach vs ForEach-Object when enumerating a large collection of objects.

Searching the web I found this article from Anita, that helped me.

The results was stunning!

Look at this scenario where I search for objects in the LDAP catalog and the search returns +20 thousand objects.

I got $Response.Entries.Count is 21897

I then use the Measure-Command to compare the ForEach with the ForEach-Object way of iterating the objects.

First let’s see how the  generic ForEach-Object{} is doing.

(Measure-Command{$Response.Entries | ForEach-Object{$_.DistinguishedName} }).TotalMilliseconds
Resulted in: 1020 milliseconds

And then let’s see how ForEach(){} is doing when defining the type of object in the collection

Defining the entry object type like this
[System.DirectoryServices.Protocols.SearchResultEntry]$entry

and then measuring the result

(Measure-Command{ForEach($entry in $Response.Entries){$entry.DistinguishedName} }).TotalMilliseconds
Resulted in: 98 milliseconds

A performance factor of 10!.

And since a few of my collections in this project was actually returning more than 200 thousand objects you can imagine that I actually was able to see some effect.

FIM 2010 R2 SP1 – 4.1.3114.0 – is Released

Today Microsoft made the FIM 2010 R2 SP1 release available for general download. Read all about the news in SP1 in KB2772429.

I myself ran into a situation at a customer yesterday where the binding redirect for the new version where not applied by the SP1 installer. As described in the KB this happens if some modifications has been done to the configuration files.

Updating the three files

  • miisserver.exe.config
  • mmsscrpt.exe.config
  • dllhost.exe.config

so that the bindingRedirect section had the newVersion=”4.1.0.0″ solved the problem and made the ECMA 2 adapters in the solution start working again. I actually first made the mistake of using 4.1.3114.0 as newVersion, since this is the Product Version of the new Microsoft.MetadirectoryServicesEx.dll file. But this is not the “Build Number” that we are talking about. The Build Number you need to redirect to is the 4.1.0.0 that you can see in the GAC on the Microsoft.MetadirectoryServicesEx.dll.

Working with SQL aliases

In all FIM implementations you should use SQL aliases and not point to the actual SQL server instances or servers in your configuration. The problem is that SQL aliases have two versions, one for 64-bit (the default) and one for 32-bit.

One time you will hit the 32-bit is if you are working with Visual Studio (32-bit application) or 32-bit ODBC drivers.

To manage your aliases you need to use the correct version of cliconfg.exe. If you just start a command prompt and run cliconfg you will be able to manage the 64-bit aliases. The full path is C:\Windows\System32\cliconfg.exe.

But if you need to manage the 32-bit aliases you need to start the C:\Windows\SysWOW64\cliconfg.exe.

Another problem you might run into is having to copy your alias settings from one machine to another. For example from your test FIM to your production FIM. The easiest way I have found is to copy the two registry keys that holds this information between the machines.

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo
  • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo

Hopefully this post will make it easier for you to work with your SQL aliases.

Deprecated Features and Planning for the Future of FIM

The product team has now started to reveal some news about the next version of FIM. First out is a list of deprecated features to prevent us from using them in our current projects. Making a transition to the next version easier.

Read about deprecated features in FIM on TechNet.

Positive feedback on my FIM 2010 R2 Book

I am getting lots of positive feedback from readers all over the world. Feedback that really warms my heart. I just can’t help sharing one with you.

Kent, I’m super impressed with your book. Authoritative information in combination with a collegial writing style is a rare find. One of the ways you distinguish your writing from other tech books is the way you inject little tips to help keep the boat pointed straight up the river:

FIMR2BookReferenceExample1

Looking forward to reading every page…
-Bill Boswell

Hotfix rollups for FIM 2010 and FIM 2010 R2

Microsoft has released new hotfix rollups for both FIM 2010 and FIM 2010 R2. Among other things it is said to fix the “stopped-server” error in FIM 2010 Synchronization Service.

Read more at FIM 2010 hotfix rollup (build 4.0.3627.2) and at FIM 2010 R2 hotfix rollup (build 4.1.2515.0)

FIM 2010 R2 is RTM

Yesterday FIM 2010 R2 RTM release was made available on MSDN. Within a week it should be available on all license channels.

If you have been playing around with the RC release that was available on Microsoft Connect, you will not be able to upgrade to RTM. Read about that and other interesting stuff in the FIM 2010 R2 Release Notes.

BHOLD Suite for FIM 2010 avialable for download.

Microsoft BHOLD Suite extends the capabilities of FIM 2010 by adding role-based access control to FIM 2010, enabling organizations to define user roles and to control access to sensitive data and applications in a way that is appropriate for those roles.

Yesterday the BHOLD Suite addon for FIM 2010 was made available on MSDN. Within a week it should be available on all license download sites.

Please read more about it on http://aka.ms/BHOLD.

FIM 2010 Update Rollup 2

FIM 2010 Update Rollup 2 will go live on Microsoft Update  today, February 28 at 10 am Pacific time. In addition to including all servicing changes made since RTM, this rollup:

  • Adds support for the new Extensible Connectivity Management Agent 2.0 (ECMA 2) framework
  • Addresses a possible performance issue for installations with many dynamic groups or criteria-based sets whose membership criteria include several conditions
  • Reverts a change in the previous hotfix release that treated SQL wildcard characters as literals
  • Addresses a number of other issues.

Especially interesting is the reappearing support for wildcards. Hotfix rollup 2520954 removed support for using the following characters as SQL wildcard characters in queries, in dynamic group filters, and in set filters:

  • Underscore (_)
  • Percent (%)
  • Opening bracket ([)

The functionality was used by many of my customers preventing them from updating their FIM. This hotfix reverts the earlier change.

For details, see KB2635086