Skip to content

Instantly share code, notes, and snippets.

@ril3y
Last active October 30, 2024 21:16
Show Gist options
  • Save ril3y/711c4ae3578691e7a975bdc5656d9c5a to your computer and use it in GitHub Desktop.
Save ril3y/711c4ae3578691e7a975bdc5656d9c5a to your computer and use it in GitHub Desktop.
work_profile.ps1
function sha256 {
param (
[string]$FilePath
)
# Resolve the full path if the path is relative
$resolvedPath = Resolve-Path $FilePath -ErrorAction Stop
# Check if the file exists
if (-not (Test-Path $resolvedPath)) {
Write-Host "File not found: $FilePath"
return
}
try {
# Open the file stream
$fileStream = [System.IO.File]::OpenRead($resolvedPath)
# Initialize SHA256 instance
$sha256 = [System.Security.Cryptography.SHA256]::Create()
# Compute the SHA256 hash from the file stream
$hashBytes = $sha256.ComputeHash($fileStream)
$hashString = -join ($hashBytes | ForEach-Object { "{0:x2}" -f $_ })
# Close the file stream
$fileStream.Close()
# Print the result as sha256: filename
Write-Host "sha256: $hashString : $(Get-Item $resolvedPath).Name"
} catch {
Write-Host "Error computing SHA-256: $_"
}
}
function touchy {
param (
[Parameter(Mandatory=$true)]
[string]$FilePath
)
if (-not (Test-Path $FilePath)) {
New-Item -ItemType File -Path $FilePath -Force | Out-Null
Write-Host "Created new file: $FilePath" -ForegroundColor Green
} else {
(Get-Item $FilePath).LastWriteTime = Get-Date
Write-Host "Updated timestamp for: $FilePath" -ForegroundColor Green
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment