February 2019
Intermediate to advanced
626 pages
15h 51m
English
Functions and other commands can be added to the InitialSessionState object in much the same way as variables. If a function is within a module, the module should be imported instead.
Functions, as SessionStateFunctionEntry objects, are added to the Commands property of the InitialSessionState object.
Simple functions can be added by defining the body of the function inline, as follows:
$functionEntry = [System.Management.Automation.Runspaces.SessionStateFunctionEntry]::new( 'Write-Greeting', 'Write-Host "Hello world"')$initialSessionState.Commands.Add($functionEntry)
Functions may be added with scope options in the same way as is done with variables. Scoping is rarely used with functions.
If the function already exists in ...
Read now
Unlock full access