What is the difference between a cmdlet and a function?

To complement Bruce Payette’s helpful answer: Not all functions are created equal in PowerShell: An advanced function is the written-in-PowerShell analog of a (binary) cmdlet (which, as stated, is compiled from a .NET language); decorating a function’s param(…) block with the [CmdletBinding()] attribute or decorating at least one parameter with a [Parameter()] attribute thanks, Ansgar … Read more

Return array from function

At a minimum, change this: function BlockID() { var IDs = new Array(); images[‘s’] = “Images/Block_01.png”; images[‘g’] = “Images/Block_02.png”; images[‘C’] = “Images/Block_03.png”; images[‘d’] = “Images/Block_04.png”; return IDs; } To this: function BlockID() { var IDs = new Object(); IDs[‘s’] = “Images/Block_01.png”; IDs[‘g’] = “Images/Block_02.png”; IDs[‘C’] = “Images/Block_03.png”; IDs[‘d’] = “Images/Block_04.png”; return IDs; } There are … Read more

Returning an enum from a function in C?

In C++, you could use just Foo. In C, you must use enum Foo until you provide a typedef for it. And then, when you refer to BAR, you do not use Foo.BAR but just BAR. All enumeration constants share the same namespace (the “ordinary identifiers” namespace, used by functions, variables, etc). Hence (for C): … Read more

The invocation context (this) of the forEach function call

MDN states: array.forEach(callback[, thisArg]) If a thisArg parameter is provided to forEach, it will be used as the this value for each callback invocation as if callback.call(thisArg, element, index, array) was called. If thisArg is undefined or null, the this value within the function depends on whether the function is in strict mode or not … Read more

Create a function with optional call variables

Powershell provides a lot of built-in support for common parameter scenarios, including mandatory parameters, optional parameters, “switch” (aka flag) parameters, and “parameter sets.” By default, all parameters are optional. The most basic approach is to simply check each one for $null, then implement whatever logic you want from there. This is basically what you have … Read more

Python Function to test ping

It looks like you want the return keyword def check_ping(): hostname = “taylor” response = os.system(“ping -c 1 ” + hostname) # and then check the response… if response == 0: pingstatus = “Network Active” else: pingstatus = “Network Error” return pingstatus You need to capture/’receive’ the return value of the function(pingstatus) in a variable … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)