Computer inventory report (scheduled task)

Computer inventory report (scheduled task)

# Load Active Directory Module
Import-Module ActiveDirectory
# Set Date Variable
$DateStr = Get-Date -format "yyyy-MM-dd-hh-mm"
# Export Query to Current Directory
Get-ADComputer -SearchBase 'OU=domain,dc=local' -Filter 'ObjectClass -eq "Computer"' | Select -Expand DNSHostName >> ((Get-Location).Path + "\List\Computerlist $DateStr report.txt")
# Set up Mail Communication
$users = "Dit e-mailadres wordt beveiligd tegen spambots. JavaScript dient ingeschakeld te zijn om het te bekijken." # List of users to email your report to (separate by comma)
$fromemail = "Dit e-mailadres wordt beveiligd tegen spambots. JavaScript dient ingeschakeld te zijn om het te bekijken."
$server = "x.x.x.x" #enter your own SMTP server DNS name / IP address here
# Generate the message
$body = @"
Hi there,,



Here is a montly report of our computers.



Kind regards



Your IT Team
"@

$file = ((Get-Location).Path + "\List\Computerlist $DateStr report.txt")
# Email our report out
send-mailmessage -from $fromemail -to $users -subject "Computerlijst $DateStr Monthly Report" -BodyAsHTML -body $body -attachment $file -priority Normal -smtpServer $server