Forum Discussion

rakshi's avatar
rakshi
Copper Contributor
Apr 26, 2021
Solved

The term <function-name> is not recognized as the name of a cmdlet, function, ...

This is my code. I'm trying to unzip files, edit them, and zip them back. For some reason functions DeGZip-File and GZip-File are not being recognized. Could anyone point out what could be wrong here...
  • SteveMacNZ's avatar
    Apr 26, 2021
    A few of things that jump out upon a quick glance of the code
    1 - use function names with approved verbs e.g. DeGZip-File = Invoke-DeGZip (https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.1)
    2 - the $input variable is automatic built in variable which could lead to unexpected results
    3 - on line 65 you are calling the function inside a variable with the filename in brackets - typically would pass the file to the function calling naming the parameter e.g. Invoke-DeGZip -infile $file
    4 - the infile parameter doesn't have a type would expect this to be a string value with being passed a filepath

    Not a full review of the code - I would start with editing the code in Visual Studio Code as it will pull out some of these and other warnings and errors, also look at coding good habits. like declaration of variables in a section, all functions in another section then an execution section which only contains the "running code" that calls the variables there are some good templates for PowerShell scripts that you can use to assist 🙂

Resources