Created
November 26, 2024 14:49
-
-
Save justaguywhocodes/72e3194c964181e4ec836cf632cc155b to your computer and use it in GitHub Desktop.
testscript.ps1
This file contains hidden or 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
# 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