From 681725492e9b66c4d11a63bd7bdfe054e3106239 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 26 Dec 2021 00:08:59 -0800 Subject: [PATCH] Move New-Object call into begin block It's not necessary to create this object on every loop. --- ArdisUtilities/ArdisUtilities.psm1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) -- 2.47.3