I'm trying to use code to get files in a dir and choose the one(s) that are edited in the last 4 hours. For some reason, when I debug this in VisualStudioCode, the debugger says
Supply values for the following parameters:
Process[0]:
$out_path = "C:\Data\Monitor\PropertiesReport\"
#find latest scan file (within 4 hours from now)
$output_sprdsheet_blob_path = Join-Path -Path $out_path -ChildPath "\OutputSprdsht\" #location of scan output file...looks good for path
Get-ChildItem $output_sprdsheet_blob_path -Filter *.xlsx | Foreach-Object
{
$lastupdatetime=$_.LastWriteTime
$nowtime = get-date
if (($nowtime - $lastupdatetime).totalhours -le 4)
{
Write-Host $_.Name
$excel_File_from = $_.Name
#Select-String -Path $_.Name -Pattern "'Execute Time of Send Thread = 60.'"
}
}
#use file found above next
I'm not sure why powershell gives a prompt to supply values foreach-object, when the path is valid for Get-ChildItem. I've used similar code before, and it worked, but I was using PowershellISE, and the code started with the following instead of the Get-ChildItem.
powershell "Set-Location -Path $log_path ; Get-Item *.* | Foreach {...}
I was having the same issue with the above code, where the visual studio code debugger gave the Process[0] prompt and wanted me to supply values at the foreach. This had been tested and used before as well.
I am trying the Get-ChildItem because of the example below doing this, and it looks like it should work. Any idea why the visual studio code debugger gives the prompt and how to fix it?
I have used write-host to print the dir being used, and I pasted the path printed into windows file explorer and there was a file there, and the path was valid.
My powershell version is 5.1.
Update:
This prints the filename. I'm not sure why it doesn't give the prompt.
$out_pth = "C:\Data\Monitor\PropertiesReport\"
Set-Location -Path $out_pth
Get-Item *.* | foreach-object {write-host $_.name}
Update2:
This prints the filename too:
Get-ChildItem $out_pth | Foreach-Object {write-host $_.name}