This is how you could use the using statement inside Powershell
function Using-Object
{
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[AllowEmptyCollection()]
[AllowNull()]
[object]
$InputObject,
[Parameter(Mandatory = $true)]
[scriptblock]
$ScriptBlock
)
try
{
.$ScriptBlock
}
finally
{
if ($null -ne $InputObject -and $InputObject -is [System.IDisposable])
{
$InputObject.Dispose()
}
}
}
Using-Object ($streamWriter = New-Object System.IO.StreamWriter("$SitecoreDataFolder\newfile.txt")) {
$streamWriter.WriteLine('Line written inside Using block.')
$streamWriter
}
This is how you could disable events in Sitecore
Using-Object ($ed = New-Object Sitecore.Data.Events.EventDisabler) {
# "Disbaled""Disabled"
}
Notice that a script execution triggers some events in the background (you can observe index rebuild jobs even if you run empty script).
Once you wrap something with using statement, everything what is inside should work in 'switched context', with all events disabled.
I tested it and number of items added to indexing queue is different.