-2

So I have a PowerShell script that reads certain system info and passes this to a webserver. Now I create a USB stick with several different files, but they all have the same PowerShell script. But now I would like to know which of the 10 files was clicked.

these are lnk files that link to powershell.exe with certain arguments.

Joep vg
  • 17
  • 4

1 Answers1

0

If I understand you correctly you want to know with which parameters/values your script has been run? Then you can use some automatic variable which will contain this information, like $MyInvocation or $PsBoundParameters.

As an example

function Test {
    param(
        $a,
        $b
    )

    $MyInvocation.Line
}

Test -a 3 -b 1

will return "Test -a 3 -b 1".

Olaf Reitz
  • 664
  • 3
  • 10
  • not exactly. I have for example 10 files: nr1.png.lnk till nr10.png.lnk. All these files initiate the same powershell script. What i want is to know which of these 10 files was clicked. Till now the powershell script gathers some pc data (hostname, username, etc) and sends this to a webserver. now i want to add the filename which was used, but i dont even know if this possible – Joep vg Aug 28 '17 at 17:44
  • I hoped you could identify your lnk file from the parameters you use in them. If that is not the case, the only way I can think at the moment would be to add an additional parameter to the script something like CalledBy or anything and add it into script call in the lnk files. – Olaf Reitz Aug 29 '17 at 19:25