Anonymous functions in PowerShell

PowerShell

 In PowerShell there is no need to write a return statement. 

The last evaluation is the return value.

Writing { $true } is similar to C# () => true

This syntax reminds somewhat Kotlin.

Example: disable TLS trust check:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} ;

In PowerShell terms it is named as a Script Block

Post a Comment

Previous Post Next Post