Keep it Simple

// a software developer's blog by Karthikeyan Vijayakumar

How to find the Members of a given AD Group?

Is there a command line way to list all the users in a particular Active Directory group? Yes, we can achieve this PowerShell without having to install additional plug-ins.

$groupName = “GroupName”

$users = ((net group $groupName /domain |  Where-Object { $_ -notmatch ‘^(The request|$|Group Name|Comment|Members|–|The c)’ }) -replace ‘\s+’, ‘,’ -split “,”) | where {$_ -ne “”}

So what is lock in C#?

Lock, a keyword, that protect the state of the object is being locked means that the state of the object can not be modified outside of the lock until it is released.

This is used in threading, it restricts code from being executed by more than one thread at the same time. This makes threaded programs reliable. The lock statement uses a special syntax form to restrict concurrent access.

Continue reading

Using C# code in Powershell

It would be great if the existing C# code could be reused inside Powershell without a need to implement it as Cmdlet.

And indeed the Powershell Version 2 provides a way to achieve this using the Add-Type Cmdlet which allows to generate a new .NET assembly using the provided C# source code in memory which can then be used by powershell scripts executed in the same session.

Continue reading

HTMLAgilityPack Rocks

I had to do some deep data extraction from a SharePoint List, and naturally leaned on PowerShell for some assistance. PowerShell is a great language for text munging, and web content is no different.

At that point, I remembered something called the HTML Agility Pack that I’ve been meaning to experiment with for some time. The HTML Agility Pack lets you navigate an HTML document as though it were well-formed XML, even though the underlying HTML usually isn’t. It doesn’t leverage PowerShell’s XML adapter, but the .NET objects act just like the XML classes from the .NET Framework.

On the down-side, data navigation and selection in XML comes via the XPath language. Like Regular Expressions, XPath queries are an esoteric art and difficult to get right. Luckily, you don’t need much knowledge of XPath for simple XML navigation.

Continue reading

« Older posts

© 2016 Keep it Simple

Theme by Anders NorenUp ↑