-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

2 Answers2

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
  • 684
  • 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
0
$file = Get-Item $MyInvocation.MyCommand.Path
Write-Host "The file that was clicked to open this PowerShell window is: $($file.Name)"
DSSO21
  • 109
  • 9
  • Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Feb 08 '23 at 01:29