Trying to figure out how to get Powershell to display header details on subsequent requests to the same directory path.
Here is a simplified example of what I am trying to do, note that the second call to Get-ChildItem does not display the header details (presumably because it knows its already been called previously within the same scriptblock):
PS C:\TEMP\foo> $path="c:\temp\foo";Get-ChildItem -Path $path;Write-Output "Delete something and display directory contents again...";del $path\*5*;Get-ChildItem -Path $path
Directory: C:\temp\foo
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/21/2016 9:54 PM 16 File1.txt
-a--- 9/21/2016 9:54 PM 16 File2.txt
-a--- 9/21/2016 9:54 PM 16 File3.txt
-a--- 9/21/2016 9:54 PM 16 File4.txt
-a--- 9/21/2016 9:54 PM 16 File5.txt
Delete something and display directory contents again...
-a--- 9/21/2016 9:54 PM 16 File1.txt
-a--- 9/21/2016 9:54 PM 16 File2.txt
-a--- 9/21/2016 9:54 PM 16 File3.txt
-a--- 9/21/2016 9:54 PM 16 File4.txt
This appears to be the default behavior if the same path is referenced more than once. I have found that a second header will be generated whenever a different path is provided in the second Get-ChildItem call, but never when the same path is used more than once.
Any ideas on how to force the second header to display like the first while still keeping both of these calls within the same scriptblock?
Thanks!