173
$tool = 'C:\Program Files\gs\gs9.07\bin\gswin64c.exe'

& $tool -q -dNOPAUSE -sDEVICE=tiffg4 $param -r300 $pdf.FullName -c quit

Can someone explain to me how the this works? What exactly does the & symbol do/mean in powershell?

Peter3
  • 2,549
  • 4
  • 20
  • 40

1 Answers1

173

& is the call operator which allows you to execute a command, a script, or a function.
For more details:
SS64 documentation: Call operator (&)
Microsoft Docs: Call operator &

Syntax
      & "[path] command" [arguments]

Example:

$LocalComputerName = & $ENV:windir\System32\HostName.exe

Also, if you use an IDE (such as PowerGUI) you can block it from opening a separate window when executing a secondary process:

& more
Start-Process "my_script.here"
slybloty
  • 6,346
  • 6
  • 49
  • 70
  • 3
    What is `& more` ? – Slate Jan 28 '19 at 16:39
  • 1
    @kjhf When using an IDE, if the new process you execute opens a new separate window to run in, you can hide that by using `& more`. – slybloty Jan 28 '19 at 17:46
  • 10
    See also [the official documentation](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators#call-operator-). – Franklin Yu Mar 25 '19 at 19:20
  • 4
    what is the difference between `&` and `Start-Process`? – Ooker Oct 19 '21 at 04:28
  • 2
    @Ooker `&` runs a proces in the child scope; however `Start-Process` as well as just running the command runs it in the current scope. `&` is kinda like starting a deamon. – Danon Jan 08 '22 at 17:54
  • I can't tell you why, but when using the Call operator (&) in my Powershell scripts to run uninstall commands with parameters, I need to use single quotes & 'path\to\exe' /switch when specifying the path, not double quotes. – Daikyu Aug 11 '22 at 19:50