Created
August 8, 2019 02:08
-
-
Save jeevan-vj/02c61775391b5f33f5b04c80f9408dc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Using-Object( | |
[System.IDisposable] | |
$InputObject, | |
[scriptblock] | |
$ScriptBlock = {throw "ScriptBlock is mandatory, please provide a value."}) | |
{ | |
try | |
{ | |
. $ScriptBlock | |
} | |
finally | |
{ | |
if ($null -ne $InputObject -and $InputObject -is [System.IDisposable]) | |
{ | |
$InputObject.Dispose() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment