Skip to content

Instantly share code, notes, and snippets.

View stephent23's full-sized avatar

Stephen Tate stephent23

View GitHub Profile
@stephent23
stephent23 / hashExecutingScript.ps1
Last active September 4, 2024 19:41
This retrieves the hash of the executing powershell script.
# Get Hash of Current script
$script = $MyInvocation.ScriptName
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($script)))
@stephent23
stephent23 / CustomPSErrors.ps1
Created July 11, 2016 19:33
The Gist shows two examples of custom PowerShell errors.
# Example 1 - Catch the exception that would have been thrown after a method such as connecting to a SQL database / failed network connection
$errorRecord = New-Object System.Management.Automation.ErrorRecord(
$_.Exception,
'SmallOneWordDescriptionOfError', (e.g.ConnectionFailureToDBName)
[System.Management.Automation.ErrorCategory]::ConnectionError,
$myinvocation
)
$pscmlet.ThrowTerminatingError($errrorRecord)
@stephent23
stephent23 / PSMFileExample.psm1
Created July 11, 2016 19:36
An example of a PowerShell Module file that loads all of the scripts / functions into memory
## Name of module
#
# Internal
#
[Array]$Internal = 'NameOfScript',
'NameOfScript '
if ($Internal.Count -ge 1) {
$Internal | ForEach-Object {
@stephent23
stephent23 / PS Script: SUNBURST DLL
Last active September 4, 2024 19:40
PowerShell Script to identify the SolarWinds.Orion.Core.BusinessLayer.dll on host and return the location/file hash
$path_ = "C:\"
$list = @(Get-ChildItem -Path $path_ -Name "SolarWinds.Orion.Core.BusinessLayer.dll" -Recurse)
$list | % {
$fullPath = $path_ + $_
Get-FileHash $fullPath -Algorithm SHA256 | Format-List
}