September 24, 2009

Active Directory and C# II

To continue this series of posts, I'd now like to talk about groups and my group helper class. It is actually quite simple and kind of looks just like the User helper. You can download all the files from here.
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using ActiveDs;

namespace AdLib
{
public class AdGroup : IDisposable
{
private DirectoryEntry _entry;
private IADsGroup _group;

public AdGroup(DirectoryEntry entry)
{
if (entry == null)
throw new ArgumentNullException("entry");

_entry = entry;
_group = (IADsGroup)entry.NativeObject;
}

public DirectoryEntry Entry
{
get { return _entry; }
}

public IADsGroup NativeObject
{
get { return _group; }
}

#region IDisposable Members

public void Dispose()
{
_entry.Dispose();
}

void IDisposable.Dispose()
{
Dispose();
}

#endregion
}
}
Of course, we would also need to understand what a GroupType in AD really is:
using System;
using System.Collections.Generic;
using System.Text;

namespace AdLib
{
[Flags]
public enum GroupType : int
{
Unknown = 0,
LocalDistribution = 4,
LocalSecurity = (4 | -2147483648),
GlobalDistribution = 2,
GlobalSecurity = (2 | -2147483648),
UniversalDistribution = 8,
UniversalSecurity = (8 | -2147483648)
}
}
In the next post, we will talk about domains and eventually how this all fits together.

September 23, 2009

Active Directory and C#

I have done a lot of work in the last few years with AD and C#. I figured now that I shared a whole bunch of AzMan stuff, it is only logical that I share some AD helper classes as well. Some of the code can of course be written differently now in the world of .NET 3.5. However, what is written is still relevant and works well. Like the AzMan posts, this will be a bunch of posts tied together to make an application. Unlike AzMan, this will be slower since there is a A LOT more in AD than in AzMan.

One thing that I'll point out is that I rely on ActiveDS more than DirectoryEntry....so for those against this, I am sorry :)

I'd like to start off with the AdUser class that I use from my AdLibrary which you can download from here:
using System;
using System.Collections.Generic;
using System.Text;
using ActiveDs;
using System.DirectoryServices;

namespace AdLib
{
public class AdUser : IDisposable
{
private DirectoryEntry _entry;
private IADsUser _user;

public AdUser(DirectoryEntry entry)
{
if (entry == null)
throw new ArgumentNullException("entry");

_entry = entry;
_user = (IADsUser)entry.NativeObject;
}

public DirectoryEntry Entry
{
get { return _entry; }
}

public IADsUser NativeObject
{
get { return _user; }
}

#region IDisposable Members

public void Dispose()
{
_entry.Dispose();
}

void IDisposable.Dispose()
{
Dispose();
}

#endregion
}
}
To be honest, not much can be done with this. However, combined with all the other classes in the upcoming posts you will see how it all ties together.

September 22, 2009

Powershell Recycle App Pool

I had a need for this today on a IIS 6 box and came across this post on Stack Overflow. SO always has the answer for these things. This script combined with the last post on remoting I should be able to do this from a remote machine! I'll let you know if it works.

September 21, 2009

Powershell Remoting without Admin Permissions

This article shows how it can be done by adding Powershell Session Users to the local group and setting some other permissions. This is great since before this I always was doing some form of impersonation to get this to work!

September 20, 2009

Happy Sunday!

I hope everyone has a great day today!