Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save justaguywhocodes/72e3194c964181e4ec836cf632cc155b to your computer and use it in GitHub Desktop.
Save justaguywhocodes/72e3194c964181e4ec836cf632cc155b to your computer and use it in GitHub Desktop.
testscript.ps1
# Define the path to the file you want to open
$filePath = "C:\path\to\your\file.txt"
# Check if the file exists
if (Test-Path $filePath) {
# Read all lines from the file into an array
$fileLines = Get-Content -Path $filePath
# Process each line, adding line number information
$processedContent = for ($i = 0; $i -lt $fileLines.Length; $i++) {
"This is line number $(($i + 1)): $($fileLines[$i])"
}
# Join the processed lines into one string for output
$output = $processedContent -join "`n"
# Print the processed content
Write-Output $output
} else {
Write-Output "The file does not exist at the specified path."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment