37 lines
1.2 KiB
PowerShell
37 lines
1.2 KiB
PowerShell
#Load variables
|
|
. "C:\scripts\automatic-updates-static\Variables.ps1"
|
|
|
|
#set-location C:\scripts\automatic-updates\
|
|
$KeyPath = "c:\scripts\automatic-updates-static\"
|
|
|
|
#function to get credentials from a Saved file
|
|
Function Get-SavedCredential([string]$UserName,[string]$KeyPath)
|
|
{
|
|
If(Test-Path "$($KeyPath)\$($Username).cred") {
|
|
$SecureString = Get-Content "$($KeyPath)\$($Username).cred" | ConvertTo-SecureString
|
|
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecureString
|
|
}
|
|
Else {
|
|
Throw "Unable to locate a credential for $($Username)"
|
|
}
|
|
Return $Credential
|
|
}
|
|
|
|
|
|
#Get encrypted password from the file
|
|
$cred = Get-SavedCredential -UserName $mailusername -KeyPath "c:\scripts\automatic-updates-static"
|
|
#Get FQDN for subject
|
|
$myFQDN =(Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain ; Write-Host $myFQDN
|
|
#$cred = Get-Credential backup@fourit.nl
|
|
$mailprops = @{
|
|
To = $mailto
|
|
From = $mailfrom
|
|
Subject = $myFQDN
|
|
Port = 587
|
|
SmtpServer = $smtpserver
|
|
Credential = $cred
|
|
UseSsl = $true
|
|
BodyAsHtml = $true
|
|
}
|
|
$htmlBody = 'There are no updates available'
|
|
Send-MailMessage @mailprops -body $htmlBody |