Categories:

Email
  🠪  Servers
  🠪  Testing
  🠪  Tips

Hardware
  🠪  3D Printing
  🠪  Apple
  🠪  Batteries
  🠪  Drives
  🠪  Edgerouter
  🠪  Electronics
  🠪  Laptop
  🠪  Modems
  🠪  Phone
  🠪  Printers
  🠪  Raspberry Pi
  🠪  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
October 23, 2021

# 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
October 26, 2021

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
Detect Keystrokes in console PowerShell scripts
October 25, 2021

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
October 27, 2021

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




Keywords: VS Code, Powershell ISE


Category: Scripts 🠪 Powershell
Exchange Commands
October 27, 2021

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
October 27, 2021

#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
October 28, 2021

### 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-object ...<Too long, click to read the rest>


Category: Scripts 🠪 Powershell
My Powershell scripts
October 27, 2021
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
October 26, 2021

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
October 28, 2021

GUI Builder
https://poshgui.com/Editor


Category: Scripts 🠪 Powershell
Regex
October 28, 2021

Online Regex testing
https://regex101.com/


Category: Scripts 🠪 Powershell
Sigcheck
October 23, 2021

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


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


Category: Scripts 🠪 Powershell
Signing Powershell scripts
October 23, 2021

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
Sysmon
October 28, 2021

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
October 26, 2021

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