Tried using the following script below found in another thread here but get an error message from Adaxes saying that the cmdlet is not valid --
Import-Module Adaxes
$email = "myemail@mycompany.com" # TODO modify me
$inactivityDurationThreshold = "30" # Days
$baseDN = "%distinguishedName%"
$domain = $Context.GetObjectDomain($baseDN)
function GetObjectDisplayName($objectDN)
{
$objectPath = New-Object -TypeName "Softerra.Adaxes.Adsi.AdsPath"`
-ArgumentList @($null, $objectDN)
return [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName(
$objectPath, "IncludeParentPath")
}
$htmlBuilder = New-Object "System.Text.StringBuilder"
$htmlBuilder.append("<html><head>")
$htmlBuilder.append("<meta http-equiv=""Content-Type""`
content=""text/html charset=UTF-8""></head>")
$htmlBuilder.append("<body>")
$baseObjectDisplayName = GetObjectDisplayName($baseDN)
$htmlBuilder.appendFormat(
"<p>Inactive Users (<b>{0}</b>)</p>",
$baseObjectDisplayName)
$htmlBuilder.append("<table width=""100%%"" border=""1"">")
$htmlBuilder.append("<tr>")
$htmlBuilder.append("<th>User Name</th>
<th>Parent</th><th>Last Logon</th>")
$htmlBuilder.append("</tr>")
# Find inactive users
$users = Search-AdAccount -AccountInactive `
-TimeSpan $inactivityDurationThreshold `
-SearchBase $baseDN -UsersOnly `
-Server $domain -AdaxesService localhost
if ($users)
{
foreach ($user in $users)
{
$user = Get-AdmUser $user -Properties "LastLogonDate"`
-Server $domain -AdaxesService "localhost"
$userDN = New-Object "Softerra.Adaxes.Ldap.DN" $user.DistinguishedName
$parentDisplayName = GetObjectDisplayName($userDN.Parent.ToString())
$htmlBuilder.append("<tr>")
$htmlBuilder.appendFormat("<td>{0}</td>", $user.Name)
$htmlBuilder.appendFormat("<td>{0}</td>", $parentDisplayName)
$htmlBuilder.appendFormat("<td>{0}</td>", $user.LastLogonDate)
$htmlBuilder.append("</tr>")
}
}
$htmlBuilder.append("</table>")
$htmlBuilder.append("</body></html>")
$Context.SendMail($email, "[AD Report] Inactive Users", $NULL,
$htmlBuilder.ToString())
Originally it said Search-AdmAccount was not valid, so I tested and "AdAccount" worked. Any idea what the problem is?
the exact error --
The term 'Search-AdAccount' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.