The following code I want to use to email out a list of people whos ad account is expiring. However I am receiving this error:
Search-ADAccount : 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. At C:\Users\georgeh\Desktop\ADAccount Test.PS1:8 char:18 + $Message.body = Search-ADAccount -AccountExpiring -TimeSpan "30" | Select-Objec ... + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Search-ADAccount:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Search-ADAccount : 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. At C:\Users\test\Desktop\ADAccount Test.PS1:15 char:17 + $Message.body = Search-ADAccount -AccountExpiring -TimeSpan "30" | Select-Object ... + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Search-ADAccount:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Code:
$smtpServer = "test.local"
$smtpFrom = "[email protected]"
$smtpTo = "[email protected]";
$messageSubject = "These users AD Accounts are expiring"
$Message = New-Object System.Net.Mail.mailmessage $smtpFrom, $smtpTo
$Message.Subject = $messageSubject
$content = 'TEST'
$Message.body = Search-ADAccount -AccountExpiring -TimeSpan "30" |
Select-Object Name,AccountExpirationDate |
Sort-Object AccountExpirationDate |
ConvertTo-HTML -Head $style
$Message.IsBodyHtml = $true
$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid red; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid red; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid red; padding: 5px; }"
$style = $style + "</style>"
$Message.body = Search-ADAccount -AccountExpiring -TimeSpan "30" |
Select-Object Name,AccountExpirationDate |
Sort-Object AccountExpirationDate |
ConvertTo-HTML -Head $style
$smtp = new-Object Net.Mail.SmtpClient($smtpServer)
if ($content) {
$smtp.Send($message)
}
At C:\Users\georgeh\Desktop\ADAccount Test.PS1:8 char:18 + $Message.body
and compared to this bit in the second errorAt C:\Users\test\Desktop\ADAccount Test.PS1:15 char:17 + $Message.body
is kind of confusing. – notjustme