December 9, 2015

Active Directory - Secure channel

Issue: The trust relationship between this workstation and the primary domain failed.
Solution: Test-ComputerSecureChannel -repair

If you got "Operation failed with the following exception: The user name or password is incorrect" try:
Test-ComputerSecureChannel -Repair -Credential (Get-Credential)
In credentials popup enter domain credentials.

December 8, 2015

PowerShell - send email via gmail

$User = "USER NAME"
$Password = "USER PASSWORD"
$EmailFrom = "Your email address"
$EmailTo = "Recipient address"
$Subject = "Your Subject"
$Body = "Your email body"
$SMTPServer = ""
$msg = new-object Net.Mail.MailMessage
$msg.From = $EmailFrom
$msg.Subject = $Subject
$msg.Body = $Body
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($User, $Password)