Categories:

Email
  🠪  Servers
  🠪  Testing
  🠪  Tips

Hardware
  🠪  3D Printing
  🠪  Apple
  🠪  Batteries
  🠪  Drives
  🠪  Edgerouter
  🠪  Electronics
  🠪  Laptop
  🠪  Modems
  🠪  Phone
  🠪  Printers
  🠪  Raspberry Pi
  🠪  Testing
  🠪  Virtualization

Links
  🠪  Interesting
  🠪  Media

Network
  🠪  Data
  🠪  Testing
  🠪  VPN

Scripts
  🠪  Batch
  🠪  Linux
  🠪  Powershell

Servers
  🠪  Databases
  🠪  Misc
  🠪  Website

Software
  🠪  Other

Utilities
  🠪  Backup
  🠪  Fix Issues
  🠪  Recovery

Video
  🠪  Editing

Websites
  🠪  HTML
  🠪  Testing

Windows
  🠪  Adjustments
  🠪  Issues
  🠪  Remote Desktop
  🠪  Sercurity
  🠪  Slow
  🠪  Software
  🠪  Startup

Submit Entry
Airin's Notes

Category: Scripts 🠪 Powershell
Add full size logo to images
May 24, 2022

# Call script using:
# powershell.exe -File "AddLogo.ps1" -Filename "C:\Tools\Scripts\File.jpg" -Suffix "-Honor" -TemplateFile "C:\Tools\Scripts\Batch\Template.png"


param([String]$Filename="", [String]$Suffix="", [String]$TemplateFile="")

Add-Type -AssemblyName 'System.Drawing'


if ( $psise ){
$SourceImage = "C:\Tools\Scripts\Batch\test4.jpg"
$Suffix = "-Honor"
$TemplateFile = "C:\Tools\Scripts\Batch\Template-HH.png"
}else{
$SourceImage = $Filename
if ( $Suffix.length -lt 0 ){ $Suffix = "-New" }
}




$SpacingLeft = [Math]::Round( 50 * ( $Image.width / 2400 ) )
$SpacingRight = $SpacingLeft
$SpacingTop = [Math]::Round( 50 * ( $Image.height / 2051 ) )
$SpacingBottom = [Math]::Round( 277 * ( $Image.height / 2051 ) )


Write-Host "Loading picture: $($SourceImage)"
$Image = [System.Drawing.Bitmap]::FromFile($SourceImage)


$FinalImagePath = ( ( $SourceImage | Split-Path -Parent ) + '\' + [System.IO.Path]::GetFileNameWithoutExtension($SourceImage) + $Suffix + ".jpg" )

$Template = [System.Drawing.Bitmap]::FromFile($TemplateFile)
$TemplateResized = New-Object System.Drawing.Bitmap( ( $Image.width + $SpacingLeft + $SpacingRight ).ToInt32($null) , ( $Image.Height + $SpacingTop + $SpacingBottom ).ToInt32($null) )
$TemplateGraphics = [System.Drawing.Graphics]::FromImage($TemplateResized)
$TemplateGraphics.DrawImage($Template, 0, 0, ($Image.width + $SpacingLeft + $SpacingRight ) , ( $Image.Height + $SpacingTop + $SpacingBottom ))





$FinalCanvas = [System.Drawing.Bitmap]::new( ($Image.width + $SpacingLeft + $SpacingRight ).ToInt32($null) , ( $Image.Height + $SpacingTop + $SpacingBottom ).ToInt32($null) )

$g = [System.drawing.graphics]::FromImage($FinalCanvas)
$g.Clear([System.Drawing.Color]::Black)



# Put it there
#$g.DrawImage($Image, $SpacingLeft, $SpacingTop)
#$g.DrawImage($Image, [System.Drawing.Point]::new($SpacingLeft, $SpacingTop) , [System.Drawing.Rectangle]::new(0,0,100,100) )
$g.DrawImage($Image, [System.Drawing.Rectangle]::new($SpacingLeft,$SpacingTop,$Image.width,$Image.height) , [System.Drawing.Rectangle]::new(0,0,$Image.width,$Image.height) , [System.Drawing.GraphicsUnit]::Pixel)

$g.DrawImage($TemplateResized, 0, 0)
#$g.DrawString("test")

# Save it


Write-Host "Saving picture: $FinalImagePath"
$FinalCanvas.Save($FinalImagePath, [System.Drawing.Imaging.ImageFormat]::Jpeg)


Category: Scripts 🠪 Powershell
Debugging
May 24, 2022

Debug another powershell process. I recommend using this in PSISE.
$ProcessList = Get-Process powershell
Enter-PSHostProcess -Process $ProcessList[correctindex]
Get-Runspace
Debug-Runspace -Id [RunspaceIndex]


Category: Scripts 🠪 Powershell
Delete duplicate files found with a suffix like (Copy)
May 24, 2022

$Folder = "E:\Recovered_Files"
$ScanSubfolders = $false

$SuffixForDuplicate = " - Copy"

$Files = get-childitem $Folder
$DeletedCount = 0

foreach ( $File in $Files ){
$MatchName = "$($File.BaseName)$($SuffixForDuplicate)$($File.Extension)"
$Match = $Files | Where-Object { $_.Name -eq $MatchName -and $_.Length -eq $File.Length }
if ( $Match.count -gt 0 ){
#Duplicate found!
write-host "Deleting $($Match.FullName)"
Remove-Item $Match.FullName -Force
...<Too long, click to read the rest>


Category: Scripts 🠪 Powershell
Detect Keystrokes in console PowerShell scripts
May 25, 2022

https://powershell.one/tricks/input-devices/detect-key-press

if ([Console]::KeyAvailable)
{
# read the key, and consume it so it won't
# be echoed to the console:
$keyInfo = [Console]::ReadKey($true)
# exit loop
break
}


Category: Scripts 🠪 Powershell
Determine if Powershell is running in GUI or not
May 26, 2022

if ( ! ($PSISE -or $host.name.Contains('Studio'))) {




Keywords: VS Code, Powershell ISE


Category: Scripts 🠪 Powershell
Exchange Commands
May 23, 2022

Check exchange version. The best method is to visit link below and download the health check script. Alternately, the next two commands may show (get-exchangeserver may sometimes show old version).
Get-Command Exsetup.exe | ForEach {$_.FileVersionInfo}
Get-ExchangeServer | Format-List Name,Edition,AdminDisplayVersion
https://docs.microsoft.com/en-us/exchange/new-features/build-numbers-and-release-dates?view=exchserver-2019

Get-Mailbox -Identity first.last | fl DisplayName, Name, PrimarySmtpAddress, Se...<Too long, click to read the rest>


Category: Scripts 🠪 Powershell
Hotkeys Test
May 22, 2022

#https://hinchley.net/articles/creating-a-key-logger-via-a-global-system-hoo
k-using-powershell/
Add-Type -TypeDefinition @"
using System;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;


namespace KeyLogger {
public static class Program {
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;

private static HookProc hookProc = HookCallback;
private static IntPtr hookId = IntPtr.Zero;
...<Too long, click to read the rest>


Category: Scripts 🠪 Powershell
Misc Snippets
May 25, 2022

### Text to Speech
$Path = "$env:temp\file.wav"
Add-Type -AssemblyName System.Speech
$synthesizer = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$synthesizer.SetOutputToWaveFile($Path)
$synthesizer.Speak('This is a recording.')
$synthesizer.Speak('Adding more to it')
$synthesizer.SetOutputToDefaultAudioDevice()
# Play back the recorded file
Invoke-Item $Path



### View properties of an object
Get-Process *note* | ConvertTo-Json | Out-File $env:APPDATA\GM.json ; $IE=new-objec...<Too long, click to read the rest>


Category: Scripts 🠪 Powershell
My Powershell scripts
May 24, 2022
This lists some powershell scripts I have created which may be of interest to others. To run a powershell script automatically using Task Scheduler, set the program to [ powershell.exe ] and the Add Arguments field to [ -File "PathToScript.ps1" ]. Link to more info on setting it. To run a powershell script and hide the powershell window, use this: PowerShell.exe -windowst...<Too long, click to read the rest>

Category: Scripts 🠪 Powershell
Performance and Tips
May 24, 2022

Performance comparison of ArrayList, Generic List, hashtable, ordered dictionary, hashset, and stack.
https://www.norlunn.net/2019/10/17/powershell-performance-tips/


Category: Scripts 🠪 Powershell
Powershell Script Assistance
May 24, 2022

GUI Builder
https://poshgui.com/Editor


Category: Scripts 🠪 Powershell
Regex
May 23, 2022

Online Regex testing
https://regex101.com/


Category: Scripts 🠪 Powershell
Sigcheck
May 25, 2022

This doesn't actually use Powershell YET...
C:\Tools\SysinternalsSuite\sigcheck.exe -accepteula -e -s -vt -vs -u C:\ > C:\Tools\check.txt


keywords: Sysinternals, Signature, Check, sigcheck.exe, digital signatures


Category: Scripts 🠪 Powershell
Signing Powershell scripts
May 22, 2022

https://www.darkoperator.com/blog/2013/3/5/powershell-basics-execution-policy-part-1.html

https://www.hanselman.com/blog/signing-powershell-scripts


Category: Scripts 🠪 Powershell
Swap default printers using Powershell Script
May 22, 2022

$Printers = Get-CimInstance -Class Win32_Printer
$DefaultPrinter = ""
$Printer1 = "RICOH MP C6004"
$Printer2 = "HP LaserJet 600"

foreach ( $Printer in $Printers ){
if ( $Printer.Default ){ $DefaultPrinter = $Printer.Name }
}
write-Host "Old Default printer: $($DefaultPrinter)"

if ( $DefaultPrinter -match $Printer1 ){
$NewPrinter = $Printer2
}else{
$NewPrinter = $Printer1
}
foreach ( $Printer in $Printers ){
if ( $Printer.Name -match $NewPrinter ){
Invoke-CimMethod -InputObject $Printer -M...<Too long, click to read the rest>


Category: Scripts 🠪 Powershell
Sysmon
May 25, 2022

https://gist.github.com/psrdrgz/f87e73c4a89c4968f4ac67bf99267cc4


Sysmon is a SysInternals tool from Microsoft which allows logging of things
the computer does to the Event Log. It includes things like file
writes/creates/reads, network access, process start/stop, etc.
You can find it in the Event Viewer under:
Applications and Services\Microsoft\Windows\Sysmon\Operational

Here are some powershell commands to parse out useful information:

Get all Sysmon events, this will take a few minutes, do...<Too long, click to read the rest>


Category: Scripts 🠪 Powershell
Tray Icon Sample
May 23, 2022

https://github.com/mossrich/PowershellRecipes/blob/master/TraySnippets.ps1





This site is meant to be used as a reference for myself, although others may find it useful. I use it to keep track of certain fixes, software, and other solutions which I may need while assisting customers. The page layout is pure HTML/CSS and is kept simple to optimize loading time and fast results.

Return to Airin's Computers