From: Ardis Lu Date: Sun, 26 Dec 2021 08:08:59 +0000 (-0800) Subject: Move New-Object call into begin block X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=681725492e9b66c4d11a63bd7bdfe054e3106239;p=ArdisUtilities Move New-Object call into begin block It's not necessary to create this object on every loop. --- diff --git a/ArdisUtilities/ArdisUtilities.psm1 b/ArdisUtilities/ArdisUtilities.psm1 index ca549f2..ac2b148 100644 --- a/ArdisUtilities/ArdisUtilities.psm1 +++ b/ArdisUtilities/ArdisUtilities.psm1 @@ -271,12 +271,16 @@ function Get-SizeDurationRatio { [String]$Path ) + begin { + $shell = New-Object -ComObject Shell.Application + } + process { $resolvedPath = Resolve-Path -LiteralPath $Path $folderPath = Split-Path $resolvedPath $fileName = Split-Path $resolvedPath -Leaf - $folderObject = (New-Object -ComObject Shell.Application).NameSpace($folderPath) + $folderObject = $shell.NameSpace($folderPath) $fileObject = $folderObject.ParseName($fileName) $durationString = $folderObject.GetDetailsOf($fileObject, 27)