Send e-mail with powershell

 Create a file with ps1 extension, like send_mail.ps1, with this content:


# Make Windows negotiate higher TLS version:
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Send-MailMessage -From from@example.com -To to@example.com -Credential (Get-Credential) -Subject "Hello World" -Body "Your text here" -SmtpServer "smtp.office365.com" -Port 587 -UseSsl 

 

 With cred:

# Make Windows negotiate higher TLS version:
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
$EmailTo = "myself@gmail.com"
$EmailFrom = "me@mydomain.com"
$Subject = "Test"
$Body = "Test Body"
$SMTPServer = "smtp.gmail.com"

Send-MailMessage -From $EmailFrom -To $EmailTo -Credential $Cred -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Port 587 -UseSsl

Wget behind proxy

 

Add this lines in /etc/wgetrc file

use_proxy=yes
http_proxy=http://<proxy>:<port>
https_proxy=http://
<proxy>:<port>

 

Powershell remove confirm action

 

If you are using Remove-Item cmdlet use confirm switch like in below example

Remove-Item .\v.txt -Confirm:$false

 

 

 

WMI filter by OS Name

 

For Windows 10 in general:
Select * from Win32_OperatingSystem WHERE Caption LIKE 'Microsoft Windows 10%'

Example for english Windows 7, Server 2008r2 and 10 (but not Windows 8.x or 2008):
Select * from Win32_OperatingSystem WHERE (Caption LIKE 'Microsoft Windows 7%' OR Caption LIKE ‘Microsoft Windows Server 2008 R2%' OR Caption LIKE 'Microsoft Windows 10%’) AND OSLanguage = 1033

Simple Active Directory health test

Dcdiag.exe /v >> c:temppre_dcdiag.txt
This is a must and will always tell you if there is trouble with your DCs and/or services associated with it

Netdiag.exe /v >> c:temppre_Netdiag.txt
This will let me know if there are issues with the networking components on the DC.  This along with the post test also is a quick easy way to ensure the patch I just installed is really installed (just check the top of the log)

Netsh dhcp show server >> c:temppre_dhcp.txt
Some may not do this but I”ve felt the pain of a DHCP server somehow not being authorized after a patch.  This allows me verify the server count and names.

Repadmin /showreps >> c:temppre_rep_partners.txt
This shows all my replication and if it was successful or not.  Just be aware that Global Catalogs will have more info here than a normal domain controller.

repadmin /replsum /errorsonly >> c:temppre_repadmin_err.txt
This is the one that always takes forever but will let you know who you are having issues replicating with.


Updatable objects appear as 'no longer supported'

  Symptoms In some scenarios, the following validation warning appears on an updatable object: " Object is no longer supported. Enforci...

Mais vistos