forked from jjmolerof/PowerShellScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ADPCReport.ps1
More file actions
12 lines (12 loc) · 858 Bytes
/
Copy pathGet-ADPCReport.ps1
File metadata and controls
12 lines (12 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
$ReportDate = Get-Date -format ddMMyyyy
$smtpServer="SMTP_SERVER_IP_OR_DNS"
$MailTo="MailToAddress@example.com"
$MailFrom="MailFromAddress@example.com"
$MailSubject="Domain PC Report - $ReportDate"
$MailBody="CSV Report of current domain joined workstation and servers. Run date - $ReportDate"
$SearchBase="OU=Workstations,DC=example,DC=com"
$ExportPath="C:\Report\"
$KeepHistory=$true
Get-ADComputer -SearchBase $SearchBase -Filter * -Properties * | select Name,OperatingSystem,OperatingSystemServicePack,@{Name = "OU"; Expression = {$_.CanonicalName -replace $_.Name,''}},whenChanged | Export-Csv $ExportPath$ReportDate.csv -NoTypeInformation
Send-MailMessage -To $MailTo -From $MailFrom -Subject $MailSubject -Body $MailBody -Attachments $ExportPath$ReportDate.csv -SmtpServer $smtpServer
if (!$KeepHistory) {Remove-Item $ExportPath$ReportDate.csv -Force}