Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How do I pull an objects extensionattribute and then convert that attribute into readable format?

$
0
0

New to Powershell and still figuring out the basics.

We are monitoring the Lost and Found OU and need to notify the admins when an object is in there. However, we'd like to know WHO to contact before we delete the object, and we use extensionattribute6 OR extensionattribute 10 (6 for users, 10 for computers) as the "created by." Instead of just generating an email to my team with the object name followed by "A05858530," how do I pull the extension attribute from each individual object in the lost and found, and translate that attribute into a readable name?

I don't know if this helps, but here is the automated script used. We pump out the list into a txt, and then the automated email looks at the text file to see if it needs to send out another email. Is there a way we also pump out the extensionattributes into the email, and then have the script look at those attributes and then run them against the below ldapfilter whether the ext6 or ext10 exists?

import-module activedirectory
$test = get-adobject -filter 'name -like "*"' -searchbase 'CN=lostandfound,DC=xxxxx,DC=com' 
foreach ($entry in $test){
 if ($entry.Name -notlike "lostandfound"){$entry | format-list -property name, samaccountname, objectclass, lastknownparent, whenchanged, whencreated | Out-File C:\xxxx\LostAndFoundResults.txt -append}
}
$checkfile = Get-Content C:\xxxxx\LostAndFoundResults.txt
if ($checkfile -notlike $null){
$FromAddress = "xxxxxTeam@xxxx.com"
$ToAddress = "xxxx.xxxx@xxxx.com"
$MessageSubject = "The following is listed in the Lost & Found OU"
$body = "Please remediate accordingly." + "`r`n " + "`r`n "
$body += [string]::join([environment]::NewLine, $checkfile) + "`r`n " + "`r`n "
$body += "**PLEASE DO NOT REPLY**"
$MessageBody = $body
$SendingServer = "mailhost.xxxxx.com" 
 $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, 
 $MessageSubject, $MessageBody
  $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
  $SMTPClient.Send($SMTPMessage)
 $null | Out-File C:\xxxx\LostAndFoundResults.txt
}
How do I mix that automated script with the following?

Get-aduser–ldapfilter“(extensionattribute6=xxxxx” |selectsamaccountname

Thank you!





Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>