Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Format list from a variable.

$
0
0

Hello.

This is to see what passwords are running out.

It works, I get the e-mail with the correct data but it's in one line in the e-mail.

I would like it to fl...

If I just have $data it's o.k but the format is wrong:

$body = $data  

-------------------------------------------------------------------------------------------

$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()

$root = $dom.GetDirectoryEntry()

$search = [System.DirectoryServices.DirectorySearcher]$root

$search.Filter = "(objectclass=domainDNS)"

$result = $search.FindOne()

$t = New-Object System.TimeSpan([System.Math]::ABS($result.properties["maxpwdage"][0]))

$d = ($t.Days)* -1   ## max password age days ago

$d1 = $d +7   ## 7 days on from max password age

$data = Get-QADUser -IncludeAllProperties | Where {($_.PwdLastSet -gt (Get-Date).AddDays($d)) -and ($_.PwdLastSet -lt (Get-Date).AddDays($d1)) } 

$emailFrom = "###@###.##"

$emailTo = "###@###.##"

$subject = "Passwords"

$body = Format-List -InputObject $data    

$smtpServer = "###"

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$smtp.Send($emailFrom, $emailTo, $subject, $body)

------------------------------------------------------------------

When I use: $body = Format-List -InputObject $data    

I get this in the e-mail:

Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData

Any help would be great.

Thanks. :)


Armann Jakob Palsson

Viewing all articles
Browse latest Browse all 21975

Trending Articles



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