Could someone help me log the actual PowerShell command issued along with arguments.
I have a cmdlet implemented in C# as follows
class GetMyCommand : PSCmdlet
{
// parameter definitions
...
void processRecord()
{
// Here I want print actual arguments passed to the cmdlet.
}
}
if someone calls
Get-MyCommand -Name Hello -File "test.txt"
I just want to log the command in the processRecord function.
"Get-MyCommand -Name Hello -File "test.txt""
Clearly I know the cmdlet name, but not sure how to print the exact string of arguments.
Environment.CommandLine works inside regular exes, but how to do the same in cmdlets
Thanks
Use the MyInvocation.Line
property on PSCmdlet e.g.:
void ProcessRecord() {
var line = this.MyInvocation.Line
}