LiquidObject

Purging the old login ScriptPath

In the advance in directory topologies over the years the use of batch or vbscript login scripts are slowly being phased out in favor of group policy based solutions which offer greater flexibility. Recently I had the need to purge the ScriptPath field from all users within an organization.

$myusers = Get-ADUser -Filter * -SearchBase "DC=liquidobject,DC=com" -properties ScriptPath | select-object SamAccountName,ScriptPath

Write-Host $myusers.count " users loaded."

foreach($user in $myusers)
{
    if($user.ScriptPath.length -gt 0)
    {
        Write-Host "Cleaning: " $user.SAMAccountName #" - " $user.ScriptPath
        Set-ADUser -identity $user.SAMAccountName -ScriptPath $NULL
        Sleep 0.1
    }
    else
    {
       # Write-Host "Already Clean: " $user.SAMAccountName
    }
    
}

October 17, 2012 at 3:44 pm Comments (0)

AD user counts by first letter

When planning a deployment for a number of software packages for scaling one method of balancing the number of users across a series of groups is commonly done via alphabetical groupings based upon the username.

if(Get-Module -Name ActiveDirectory){}
else{Import-Module ActiveDirectory}

function CountUsers
{
	param([String]$mychar)
	$mycount = (Get-ADUser -Filter {SAMAccountName -like $mychar} -SearchBase "OU=My Users,DC=LiquidObject,DC=com" | Select-Object SAMAccountName).count
	Write-Host "" $mychar.SubString(0,1) " has: " $mycount " users."
}


CountUsers("A*")
CountUsers("B*")
CountUsers("C*")
CountUsers("D*")
CountUsers("E*")
CountUsers("F*")
CountUsers("G*")
CountUsers("H*")
CountUsers("I*")
CountUsers("J*")
CountUsers("K*")
CountUsers("L*")
CountUsers("M*")
CountUsers("N*")
CountUsers("O*")
CountUsers("P*")
CountUsers("Q*")
CountUsers("R*")
CountUsers("S*")
CountUsers("T*")
CountUsers("U*")
CountUsers("V*")
CountUsers("W*")
CountUsers("X*")
CountUsers("Y*")
CountUsers("Z*")
CountUsers("0*")
CountUsers("1*")
CountUsers("2*")
CountUsers("3*")
CountUsers("4*")
CountUsers("5*")
CountUsers("6*")
CountUsers("7*")
CountUsers("8*")
CountUsers("9*")
,
October 14, 2012 at 3:40 pm Comments (0)