Last active
October 30, 2024 21:16
-
-
Save ril3y/711c4ae3578691e7a975bdc5656d9c5a to your computer and use it in GitHub Desktop.
work_profile.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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