Wednesday, December 10, 2008

Just wrote my first real Powershell script

I wrote a script that searches an Active Directory group recursively for any nested groups that includes sender restrictions.


function GroupMembers
{
$adsistr = "LDAP://" + $args[0]
$group = [ADSI]$adsistr
if ($group.objectcategory -eq "CN=Group,CN=Schema,CN=Configuration,DC=domain,DC=local")
{
if ($group.authorig -ne $null)
{
$group.name
}
foreach ($member in $group.member)
{
GroupMembers $member
}
}
}
GroupMembers "cn=dl-all users,ou=groups,dc=domain,dc=local"


I actually wrote the script in Visual Basic script first, and then translated it into Powershell. While I've been doing well with various Powershell cmdlets with very simple logic one liners, I really don't consider them scripts. I've been trying to become proficient with Powershell for a while, and now I think I've found a way to do it. I think that I'll take some of my old standby Visual Basic scripts and rewrite them in Powershell.

No comments: