I have written a GUI app in PowerShell. It has one parameter.
At the beginning of the script I have:
param (
[string]$Path
)
Before the Form appears, I fill in a control with $Path
:
$Form.Add_Load({
$txtSourceFile.Text = $Path
})
When I run the script interactively in PowerShell it seems to be working as expected. The txtSourceFile
control is filled in with the argument from the command line.
.\ghead.ps1 -Path C:\src\data\ghead.ps1
However, when I run this as a File Explorer extension, it does not appear to receive the argument from the command line. The registry setting for the command is:
C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.EXE C:\\Users\\lit\\bin\\ghead.ps1 -Path %1
There is no error message. It simply does not fill in the $txtSourceFile.Text
field. Am I missing something obvious? How can I get this to work?
The question suggested as a duplicate does not deal with running as a Windows File Explorer extension. I am already using the param() technique.
The core of the problem was an extraneous character in the Users
directory name which was not presented in the question. The OP probably needs new glasses glued to his face so that he can see better and not go without them.
C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.EXE -Command C:\Users\pwatson\bin\ghead.ps1 -Path
The final registry entry turned out to be:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -WindowStyle Hidden -Command \\ASERVER\D$\Install\Utilities\ghead.ps1 -Path %1