< Back

Register-AutoDispose

Wed Jan 15, 2020 4:22 am

NAME Register-AutoDispose



SYNOPSIS

Registers to invoke the $InputObject's Dispose() method once the $ScriptBlock execution completes.





SYNTAX

Register-AutoDispose [-InputObject] <Object[]> [-ScriptBlock] <ScriptBlock> [-WhatIf] [-Confirm]

[<CommonParameters>]





DESCRIPTION

Provides equivalent functionality to C#'using statment, invoking Dispose after

executing the $ScriptBlock specified.





PARAMETERS

-InputObject <Object[]>

The object on which to find and invoke the Dispose method.



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-ScriptBlock <ScriptBlock>

The ScriptBlock to execute before calling the $InputObject's dispose method.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





If a $ScriptBlock takes a parameter, the parameter value will be set to the value of $InputObject.



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Register-AutoDispose (Get-TempFile) { Get-ChildItem }



Calls the return from Get-TempFile's Dispose() method upon completion of Get-ChildItem.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>













-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Register-AutoDispose (Get-TempFile) { param($tempFile) Write-Output $tempFile }



Calls the return from Get-TempFile's Dispose() method upon completion of Write-Output $inputObject.

In this case, because the $ScriptBlock accepts a parameter, the parameter will be initialized

with the value of $inputObject











RELATED LINKS





CommonParameters : True

WorkflowCommonParameters : False

details : @{name=Set-IsWindowsVariable; noun=; verb=}

Syntax : @{syntaxItem=System.Object[]}

parameters : @{parameter=System.Object[]}

inputTypes : @{inputType=}

returnValues : @{returnValue=}

aliases : None



remarks : None

alertSet :

description :

examples :

Synopsis :

Set-IsWindowsVariable [-WhatIf] [-Confirm] [<CommonParameters>]



ModuleName : IntelliTect.Common

nonTerminatingErrors :

xmlns:command : http://schemas.microsoft.com/maml/dev/command/2004/10

xmlns:dev : http://schemas.microsoft.com/maml/dev/2004/10

xmlns:maml : http://schemas.microsoft.com/maml/2004/10

Name : Set-IsWindowsVariable

Category : Function

Component :

Role :

Functionality :