]> git.ardis.lu - ArdisUtilities/commitdiff
Move New-Object call into begin block
authorArdis Lu <ardisglu@gmail.com>
Sun, 26 Dec 2021 08:08:59 +0000 (00:08 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sun, 26 Dec 2021 08:08:59 +0000 (00:08 -0800)
It's not necessary to create this object on every loop.

ArdisUtilities/ArdisUtilities.psm1

index ca549f23e6b35272974e06662e676473f6c6e9f1..ac2b148226246847f1281a1ece52d1cb88a64782 100644 (file)
@@ -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)
This page took 0.041759 seconds and 4 git commands to generate.