Fetches "Preference" variable values from the caller's scope.
Get-CallerPreference -Cmdlet <Object> -SessionState <SessionState> [<CommonParameters>]
Get-CallerPreference -Cmdlet <Object> -SessionState <SessionState> [-Name <String[]>] [<CommonParameters>]
| Name | Alias | Description | Required? | Pipeline Input | Default Value |
|---|---|---|---|---|---|
| Cmdlet | The $PSCmdlet object from a script module Advanced Function. | true | false | ||
| SessionState | The $ExecutionContext.SessionState object from a script module Advanced Function. This is how the Get-CallerPreference function sets variables in its callers' scope, even if that caller is in a different script module. | true | false | ||
| Name | Optional array of parameter names to retrieve from the caller's scope. Default is to retrieve all Preference variables as defined in the about\_Preference\_Variables help file \(as of PowerShell 4.0\) This parameter may also specify names of variables that are not in the about\_Preference\_Variables help file, and the function will retrieve and set those as well. | false | true \(ByValue\) |
- String
- None. This function does not produce pipeline output.
Import Preference variables from the caller of a Script Module function https://gallery.technet.microsoft.com/scriptcenter/Inherit-Preference-82343b9d MICROSOFT LIMITED PUBLIC LICENSE
EXAMPLE 1
Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState
Imports the default PowerShell preference variables from the caller into the local scope. EXAMPLE 2
Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState -Name 'ErrorActionPreference','SomeOtherVariable'
Imports only the ErrorActionPreference and SomeOtherVariable variables into the local scope. EXAMPLE 3
'ErrorActionPreference','SomeOtherVariable' | Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState
Same as Example 2, but sends variable names to the Name parameter via pipeline input.
Returns $true if hostname represents local PC.
Test-IsLocalhost [[-ComputerName] <String>] [<CommonParameters>]
| Name | Alias | Description | Required? | Pipeline Input | Default Value |
|---|---|---|---|---|---|
| ComputerName | false | false |
Dispose an object after using it.
Use-Object [-InputObject] <Object> [-ScriptBlock] <ScriptBlock> [<CommonParameters>]
| Name | Alias | Description | Required? | Pipeline Input | Default Value |
|---|---|---|---|---|---|
| InputObject | Object to be disposed. | true | false | ||
| ScriptBlock | Script to be executed. | true | false |
EXAMPLE 1
$text = ""
C:\PS> $fileStream = New-Object System.IO.FileStream("G:\test\1.txt", [System.IO.FileMode]::Open)
C:\PS> Use-Object $fileStream `
{
$streamReader = New-Object System.IO.StreamReader($fileStream)
Use-Object $streamReader `
{
$text = $streamReader.ReadToEnd()
}
}
C:\PS> $text