Search notes:

Powershell: Create a Script Block

The following function crate-script-block creates a script block that captures the value of the parameter $var with which it was created.
In order for this to work, GetNewClosure must be executed on the initial script block.
The returned scrip block also takes a parameter which is assigned when the script block is executed.
function create-script-block {
   param ($var)

   return {
      param($p)
      write-host "p = $p, var = $var"
   }.GetNewClosure()
}


$s1 = create-script-block  42
$s2 = create-script-block 'hello world'

& $s1 'one'
& $s2 'two'

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:51 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(51): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(66): id_of(Object(PDO), 'uri', '/notes/Windows/...') #2 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1788368650, '216.73.217.21', 'Mozilla/5.0 App...', NULL) #3 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/scriptblock/create(54): insert_webrequest() #4 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 51