# Initialize an array to hold the computer details
$computerDetails = @()
# Function to get disk space details
function Get-DiskSpace {
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType = 3" | ForEach-Object {
[PSCustomObject]@{
'Drive' = $_.DeviceID
'Total Disk Space' = "{0:N1} GB" -f ($_.Size / 1GB)
'Available Disk Space' = "{0:N1} GB" -f ($_.FreeSpace / 1GB)
}
}
}
# Get the current computer's IP address
$ipAddress = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '169.*' -and $_.IPAddress -notlike '127.*' }).IPAddress
# Get the last and next Windows update dates
$lastUpdate = (Get-HotFix | Sort-Object -Property InstalledOn -Descending | Select-Object -First 1).InstalledOn
$nextUpdate = (Get-Date).AddDays(30).ToString("MM-dd-yyyy") # Placeholder for next update date
# Get disk space information
$diskSpaces = Get-DiskSpace
# Populate the details for each drive
foreach ($disk in $diskSpaces) {
$computerDetails += [PSCustomObject]@{
Date = (Get-Date).ToString("MM-dd-yyyy")
Server = $env:COMPUTERNAME
IP = $ipAddress
'Total Disk Space' = $disk.'Total Disk Space'
'Available Disk Space' = $disk.'Available Disk Space'
'Last Windows Update' = $lastUpdate.ToString("MM-dd-yyyy")
'Next Windows Update' = $nextUpdate
}
}
# Convert computer details to HTML for email body
$emailBody = $computerDetails | ConvertTo-Html -Fragment | Out-String
# Email parameters
$smtpServer = "smtp.office365.com" # Replace with your SMTP server
$smtpFrom = "servicedesk@outlook" # Replace with sender email
$smtpTo = "servicedesk@outlook" # Replace with recipient email
$subject = "Computer Details Report - $(Get-Date -Format 'MM-dd-yyyy')"
$smtpPort = 587 # Common port for STARTTLS
$username = "servicedesk@rencata.com" # SMTP username
$password = "@@@@@@" # SMTP password
# Create the SMTP client and configure it
$smtpClient = New-Object System.Net.Mail.SmtpClient($smtpServer, $smtpPort)
$smtpClient.EnableSsl = $true
$smtpClient.Credentials = New-Object System.Net.NetworkCredential($username, $password)
# Create the mail message
$mailMessage = New-Object System.Net.Mail.MailMessage($smtpFrom, $smtpTo, $subject, $emailBody)
$mailMessage.IsBodyHtml = $true
# Send the email
$smtpClient.Send($mailMessage)
# Display the computer details in a table format (optional)
$computerDetails | Format-Table -AutoSize -Wrap