I'm trying to start a job that creates a file. But it doesn't.
here's the very simple code:
start-job -ScriptBlock { "hi" | set-content "hi.txt" }
The file "hi.txt" never gets created.
Why not?
I'm trying to start a job that creates a file. But it doesn't.
here's the very simple code:
start-job -ScriptBlock { "hi" | set-content "hi.txt" }
The file "hi.txt" never gets created.
Why not?
It is most likely creating the file, just not where you expect because you used a relative path. Try executing this to see where the file is going:
Start-Job {$pwd} | Receive-Job -Wait
Better yet, use an absolute path:
Start-Job { 'hi' > c:\hi.txt }
Or pass in the desired path:
Start-Job {param($path) 'hi' > "$path\hi.txt"} -arg $pwd