The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

InvocationInfo.InvocationName Property


Updated: April 27, 2016

Applies To: Windows PowerShell

Gets the name of the command that was invoked.

Namespace:   System.Management.Automation
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

public string InvocationName { get; internal set; }

Property Value

Type: System.String

A String that contains the name of the command that was invoked. For example, this could be a cmdlet name, a function name, or an alias that references a cmdlet or function.

The following code sample, pulled from the Runspace04 code sample in the SDK, displays InvocationName as part of an exception description.

private static void Main(string[] args)
      // Create a PowerShell object.
      using (PowerShell powershell = PowerShell.Create())
        // Add the commands to the PowerShell object.

        // Run the commands synchronously. Because of the bad regular expression,
        // no objects will be returned. Instead, an exception will be thrown.
          foreach (PSObject result in powershell.Invoke())
            Console.WriteLine("'{0}'", result.ToString());

          // Process any error records that were generated while running the commands.
          Console.WriteLine("\nThe following non-terminating errors occurred:\n");
          PSDataCollection<ErrorRecord> errors = powershell.Streams.Error;
          if (errors != null && errors.Count > 0)
            foreach (ErrorRecord err in errors)
              System.Console.WriteLine("    error: {0}", err.ToString());
        catch (RuntimeException runtimeException)
          // Trap any exception generated by the commands. These exceptions
          // will all be derived from the RuntimeException exception.
                        "Runtime exception: {0}: {1}\n{2}",

      System.Console.WriteLine("\nHit any key to exit...");
Return to top

Community Additions