February 17, 2023, 1:44 pm
This powershell function is not mine, but I kept it as I found it useful from time to time.
function Send-WOL
{
<#
.SYNOPSIS
Send a WOL packet to a broadcast address
.PARAMETER mac
The MAC address of the device that need to wake up
.PARAMETER ip
The IP address where the WOL packet will be sent to
.EXAMPLE
Send-WOL -mac 00:11:32:21:2D:11 -ip 192.168.8.255
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,Position=1)]
[string]$mac,
[string]$ip="255.255.255.255",
[int]$port=9
)
$broadcast = [Net.IPAddress]::Parse($ip)
$mac=(($mac.replace(":","")).replace("-","")).replace(".","")
$target=0,2,4,6,8,10 | % {[convert]::ToByte($mac.substring($_,2),16)}
$packet = (,[byte]255 * 6) + ($target * 16)
$UDPclient = new-Object System.Net.Sockets.UdpClient
$UDPclient.Connect($broadcast,$port)
[void]$UDPclient.Send($packet, 102)
}
February 17, 2023, 1:42 pm
Get-ADUser -Filter * -Properties * | `
Select-Object Name,Enabled, @{Name="Last Successful Logon";Expression={[datetime]::FromFileTime($_.'lastLogonTimeStamp')}} | `
Sort-Object "Last Successful Logon"
February 17, 2023, 1:40 pm
#View a list of groups
Get-Group
#Set GroupName before running
Get-DistributionGroupMember -Identity "GroupName"| Export-Csv C:\Users\username\Desktop\groups.csv
February 17, 2023, 1:18 pm
This will remove drivers of working, but disconnected devices. (e.g. USB Drives Printers, old video devices, etc).
FOR /L %G in (1,1,999) do PnPutil.exe -D oem%G.inf
For further cleanup: I recommend Device Cleanup Tool from Uwe Sieber. You can get it from their website.
https://www.uwe-sieber.de/english.html
February 17, 2023, 1:12 pm
VBoxManage setextradata “Name of Guest VM” VBoxInternal2/EfiGraphicsResolution 1920x1080
February 17, 2023, 1:08 pm
This example sends Windows Backup logs
$Yesterday = (Get-Date) - (New-TimeSpan -Day 1)
$logs = Get-WinEvent -logname Microsoft-Windows-Backup | Where-Object {$_.TimeCreated -ge $Yesterday}
$username = "user@domain.com"
$password = "mypassword"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
$errorCount = 0
foreach($Event in $logs)
{
$Errorlevel=$Event.LevelDisplayName
if ($Errorlevel -eq "Error")
{
$errorCount++
}
}
$body = "<html>"
$style = "<style>BODY{background-color:white;}.error{color: red;font-weight: bold;}table, th, td{border: 1px solid black;border-collapse: collapse;padding: 5px;}</style>"
$head = "<head>$style</head>"
$body += $head
$body += "<body>"
$body += "<h2>$env:computername Backup Logs</h2>"
if ($errorCount -gt 0)
{
$body += "<h3 class=""error"">$errorCount Errors</h3>"
}
$body += "<table><tr><td>Time</td><td>Error Level</td><td>EventId</td><td>Message</td></tr>"
# Get the event Log Details
foreach($Event in $logs)
{
$Time=$Event.TimeCreated
$Errorlevel=$Event.LevelDisplayName
$EventId=$Event.Id
$Message=$Event.Message
$TableLine = "<tr><td>$Time</td><td>$Errorlevel</td><td>$EventId</td><td>$Message</td></tr>"
if($Errorlevel -eq "Error")
{
$TableLine = "<tr class=""error""><td>$Time</td><td>$Errorlevel</td><td>$EventId</td><td>$Message</td></tr>"
}
$body += $TableLine
}
$body += "</table>"
$body += "</body>"
$body += "</html>"
#echo $body
$subject = "$env:computername Backup Logs"
if ($errorCount -gt 0)
{
$subject += " - $errorCount Errors"
}
Send-MailMessage -BodyAsHTML $body `
-From me@domain.com `
-SmtpServer mail.server.com`
-Subject $subject `
-To "me@domain.com" `
-UseSsl -Credential $cred
February 17, 2023, 1:02 pm
This script can be used to send windows event logs on period basis to specific e-mail. Below example sending last 24 hours of events in the Windows Essential Licensing section.
$Yesterday = (Get-Date) - (New-TimeSpan -Day 1)
$logs = Get-WinEvent -LogName "Microsoft-Windows-Server Infrastructure Licensing/Operational" | Where-Object {$_.TimeCreated -ge $Yesterday} | Format-List | Out-String
$username = "user@domain.com"
$password = "mypassword"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
#Send-MailMessage [-Attachments ] [-Bcc ] [[-Body] ] [-BodyAsHtml]
# [-Encoding ] [-Cc ] [-DeliveryNotificationOption ]
# -From [[-SmtpServer] ] [-Priority ] [-Subject] [-To]
# [-Credential ] [-UseSsl] [-Port ] []
Send-MailMessage -Body $logs `
-From me@domain.com `
-SmtpServer mail.server.com `
-Subject "Licensing Logs" `
-To "user@domain.com" `
-UseSsl -Credential $cred
February 17, 2023, 12:58 pm
Reboot will be required after adding this to registry
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /f /v DisableAntiSpyware /t REG_DWORD /d 0x00000001