What is & in PowerShell

Use the call operator

John Savill

February 21, 2017

1 Min Read
What is & in PowerShell

Q. What is & in PowerShell?

A. & is the call operator that will execute code. Normally we just execute cmdlets as their name is in the search path however consider you save commands in a string and want those commands to execute. The call operator will do that. For example:

PS C:> $commandstorun = "get-host"PS C:> $commandstorunget-hostPS C:> & $commandstorunName : Windows PowerShell ISE HostVersion : 5.1.14393.693InstanceId : 15332c57-1c14-4752-a66c-c95bcb99fb97UI : System.Management.Automation.Internal.Host.InternalHostUserInterfaceCurrentCulture : en-USCurrentUICulture : en-USPrivateData : Microsoft.PowerShell.Host.ISE.ISEOptionsDebuggerEnabled : TrueIsRunspacePushed : FalseRunspace : System.Management.Automation.Runspaces.LocalRunspace

 

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like