Powershell 7 SDK PSCmdlet - difference between GetCmdlet and GetCommand

163 Views Asked by At

With my first C# based Powershell cmdlet I ran into an issue of how to run "existing" cmdlets from within my custom cmdlet. Along the way I found the following:

InvokeCommand.GetCmdlet("Compress-7Zip") 

and

InvokeCommand.GetCommand("Compress-7Zip")  
  1. Edit The first returns a CmdletInfo object the second a CommandInfo object
  2. GetCmdlet has a description "Returns CmdletInfo object that corresponds to the name argument"
  3. GetCommand has no description, but searching on the web I found the following on Mirosoft's website "Activity to invoke the Microsoft.PowerShell.Core\Get-Command command in a Workflow"

Why do these two methods exist and which do we use for what?

1

There are 1 best solutions below

1
On

Get-Cmdlet - Returns the CmdletInfo object that corresponds to the 'Name' argument.

Get-Command - gets all commands that are 'Installed' on the computer, including cmdlets, aliases, functions, filters, scripts, and applications.

Get-Cmdlet

https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.commandinvocationintrinsics.getcmdlet?view=powershellsdk-7.0.0

Get-Command https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-command?view=powershell-7.2