0

Is it possible to use powershell TimeStamp declared outside job, in the job so I don't have to have the same thing in the script twice? I have multiple TimeStamps, the work in the functions but not the Job. I tried $(using:TimeStamp) but that didn't work. Tried using curly brackets to "call" it. If I understand correctly TimeStamp is just a function. Is there a way to call a function declared outside a Job into it? My timestamps:

filter timestamp.SubDir {$(Get-Date -Format MM-yyyy)}
filter timestamp.FileName {$(Get-Date -Format MM-dd-yyyy)}
filter timestamp.FileStamp {$(Get-Date -Format MM/dd/yyyy_HH:mm:ss)}
Retrotube
  • 35
  • 5
  • 4
    To answer your question, yes it's possible, see [this answer](https://stackoverflow.com/a/61273544/15339544), but you should seriously consider having just 1 `function` that takes the format string as argument instead of multiple filters – Santiago Squarzon May 19 '22 at 21:10
  • 3
    Also what do you intend with `filter`? These functions don't process anything, so `filter` doesn't really serve a purpose. Filter functions are for processing pipeline input. – zett42 May 19 '22 at 21:13
  • 1
    [Here](https://stackoverflow.com/a/71887657/15339544) is an example of how you can pass multiple functions to the job's scope, basically the concept is the same but store all definitions in one array and pass the array to the job's scope. – Santiago Squarzon May 19 '22 at 21:19
  • @zett42 I just started wondering that too when I came across some reading researching this. Best answer is that is what I had that worked. Now that I just tried it without, I see it's not needed. Anytime I've seen an example of `TimeStamp` it had `filter`, so assumed that's what made it "dynamic". Thanks for questioning that. – Retrotube May 19 '22 at 21:20
  • 1
    a _filter_ is just a function with a `process` block, you can simply replace it by a _function_ that takes 1 parameter (`ValueFromPipeline`) to receive the output from your (`plink.exe` ? iirc) from the pipeline and 1 parameter that takes the `DateTime` format string as argument. – Santiago Squarzon May 19 '22 at 21:23

0 Answers0