r/PowerShell • • Jan 29 '26

Question Doesn't work from the command line

$InputFile = "E:\turnOffCharge.txt"

$OutputFile = "E:\sendOFF.txt"

$TodayDate = Get-Date -Format "yyyy-M-dd"

We read the file, filter the lines containing today's date, and save it.

Get-Content -Path $InputFile | Where-Object { $_ -like "*$TodayDate*" } | Set-Content -Path $OutputFile

0 Upvotes

11 comments sorted by

View all comments

3

u/jsiii2010 Jan 29 '26 edited Jan 29 '26

Works for me.

$InputFile = "turnOffCharge.txt"
$OutputFile = "sendOFF.txt"
$TodayDate = Get-Date -Format "yyyy-M-dd"
"hi $todaydate there" | set-content $inputfile  # making example input file
Get-Content -Path $InputFile | Where-Object { $_ -like "*$TodayDate*" } |
  Set-Content -Path $OutputFile
get-content $outputfile

hi 2026-1-29 there