I can't even get the referenced script to run. Not sure what the issue is. The failure I'm getting is:
*PS C:\Windows\system32> Y:\windows-utils\Bruce_scripts\mmc_sspr_enrolled.ps1
GAC Version Location
--- ------- --------
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Softerra.Adaxes.Adsi\3.7.11926.0__43a637781bd9a3c2\Softerra.Adaxes.Adsi.dll
New-Object : Cannot find type [Softerra.Adaxes.Adsi.Search.DirectorySearcher]: verify that the assembly containing this type is loaded.
At Y:\windows-utils\Bruce_scripts\mmc_sspr_enrolled.ps1:9 char:13
+ $searcher = New-Object "Softerra.Adaxes.Adsi.Search.DirectorySearcher ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand*
Followed by a bunch of errors about the object not having the property.
Here's the script:
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$to = "johnson@pharmacy.arizona.edu" # TODO: modify me
$subject = "MMC Users Enrolled for Password Self-Service" # TODO: modify me
$reportHeader = "<h3><b>Users enrolled for Password Self-Service:</b></h3><br/><table border='0'>" # TODO: modify me
$reportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me
# Search all enabled users
$searcher = New-Object "Softerra.Adaxes.Adsi.Search.DirectorySearcher" $NULL, $False
$searcher.SearchParameters.PageSize = 500
$searcher.SearchParameters.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.SearchParameters.Filter = "(&(sAMAccountType=805306368)(memberOf='MedicarePtD')(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"
$searcher.SearchParameters.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.VirtualRoot = $True
# Find enrolled users
try
{
$searchResult = $searcher.ExecuteSearch()
$users = $searchResult.FetchAll()
$userNumber = 0
foreach ($userID in $users)
{
$user = $Context.BindToObject($userID.AdsPath)
if ($user.IsEnrolled)
{
# Add user to report
$userNumber++
$userName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($user, 'IncludeParentPath')
$reportHeader += "<tr><td>$userNumber.</td><td>$userName</td><td> Is Enrolled</td></tr>"
}
else {
# Add user to report
$userNumber++
$userName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($user, 'IncludeParentPath')
$reportHeader += "<tr><td>$userNumber.</td><td>$userName</td><td>Is NOT Enrolled</td></tr>"
}
}
$reportHeader += "</table>"
}
finally
{
$searchResult.Dispose()
}
# Build report
$htmlBody = $reportHeader + $reportFooter
# Send mail
$Context.SendMail($to, $subject, $NULL, $htmlBody)