I am writing a PS script to check user accounts in a specific group for AccountExpirationDate. Once I have determined if the account meets my timeline, I then run the account through some if, elseif, else statements. This will generate an email to the manager of the user account notifing them that the account is about to expire. Then I want to create a file with this information in it for the Security Team to follow-up on. As you can imaging, I don't want to flood the Security Team with a lot of emails, so I wish to put all the exceptions into a file and then send one email to the Security Team. So far so good...
So my problem lies in creating the file and appending to it. I would like to format the file in table like format. My thought was to create a CSV file and use this to create the table for the Security email. I have the following line of script to grab information... (just a sniplet of the script)
elseif ($_.AccountExpirationDate -le $trigger3 -and $_.AccountExpirationDate -gt $now) {
$contact = $_.manager
If ($_.manager){
$conman = Get-ADUser $contact -Properties mail,displayname
$condispname = $conman.displayname
$conmail = $conman.mail
$_ | Select-Object Name,Displayname,Created,AccountExpirationDate,{Get-ADUser $contact -Properties mail | Select-Object mail} | ConvertTo-Csv | select -Skip 2 | out-file $odirectory\$o3m -append
}
I get the line of output in the file that I am looking for, but the email address comes out like this...
"111222","Temp Test","8/26/2011 12:54:09 PM","10/2/2012 12:00:00 AM","@{mail=121212@email.org}"
How do I pull the email without the @{ } ?
Any ideas would be most helpful. Or if you see that I am going about this all wrong, that would be helpful too. :-)