Try Hard to Learn Powershell Error "The Hash Literal Was Incomplete."
Get-Process S* | Where {S$_. Path} | Dir | Sort Lastwritetime | Format-Table Fullname, Name, @{Label="Lastwritetime"; Expr={$_. Lastwritetime} Error: the Hash...
Get-Process s* |
where {s$_.Path} |
dir |
sort LastWriteTime |
Format-Table fullname, name,@{label="LastWriteTime";Expr={$_.LastWriteTime}
Error:
The hash literal was incomplete.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : IncompleteHashLiteral
Could You please give me a hint how to rewrite, please?
1 Answer
You missed a curly brace. But there's more problems in your code. It is not possible to pipe a System.Diagnostics.Process object to 'dir'
I made this, which I think gives the output you want:
Get-Process s* |where {$_.Path} | ForEach-Object {Get-Item $_.Path } |
Sort-Object LastWriteTime | Format-Table fullname, name,LastWriteTime
What it does:
- Get all processes where the name start with an s and the returned object has the Path property defined
- Get the file object of each process
- sort the file objects by LastWriteTime
- Format the output