Search code examples
powershellunc

cant call powershell GUI script from unc path from a GUI


I have a powershell GUI that launches a secound ps1 file (a GUI as well) it works fine and passes the argu on to the second one without a problem when its on the C: drive im trying to use it with a UNC path of \share\service desk\sdtools.ps1 but it does not open

The below works

Function login {

$sdnum = $numInputBox.text

Start-Process "powershell.exe" -windowstyle hidden -ArgumentList "-File C:\servicedesk\sdtool.ps1 -a $sdnum"

#Close login-form so the first script will finish.
$form.Close()

}

The below never launches the second file

Function login {

$sdnum = $numInputBox.text

Start-Process "powershell.exe" -windowstyle hidden -ArgumentList "-File \\share\service desk\sdtool.ps1 -a $sdnum"

#Close login-form so the first script will finish.
$form.Close()

}

i think it is how i have encapsulated the file name but i have tried many ways and none with luck it can open the file as a text document so i do manage to get it to call the file but not to run in powershell(i have also tried it with the full path to powershell and that dosnt work)

as \share\service desk\sdtool.ps1 is the same as g:\service desk\sdtool.ps1 i have also tried that with no luck.


Solution

  • You have a space in the path, so you need to encapsulate it in quotes:

    Start-Process "powershell.exe" -NoNewWindow -ArgumentList "-File `"\\share\service desk\sdtool.ps1`" -a $sdnum"