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")
- Edit The first returns a CmdletInfo object the second a CommandInfo object
- GetCmdlet has a description "Returns CmdletInfo object that corresponds to the name argument"
- 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?
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