Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to release / unlock file from process

$
0
0

Hi there,

I create a bundle *.mpb and import this bundle to Service Manager via

Import-SCSMManagementPack myFile.mpb

If I want to create a new bundle I got the following error-msg:

PS> New-SCSMManagementPackBundle -ManagementPack "myFile.mp" -Resource "my.dll" -Name "myFile.mpb" -Force New-SCSMManagementPackBundle : the process can't access file "C:\myFile.mpb" because the
file is used by an other programm.

So I tried to release the file via handle.exe, but it doesn't work:

$handleOut = & 'D:\SysInternals\handle.exe'

foreach ($line in $handleOut) { 
              
        if ($line -match '\S+\spid:') {
            $exe = $line
            $found = $line -match '.*pid: (\d+).*'
            $spid = $matches[1]
        } 
        if($line -like "*myFile.mpb*"){"$exe - $line"
           $found = $line -match '([a-zA-Z\d]+):.*'
           $handleID = $matches[1]
           Start-Process -NoNewWindow -FilePath "D:\SysInternals\handle.exe" -ArgumentList "-c $($handleID)", "-p $($spid)"
        }  

     }
powershell_ise.exe pid: 12296 \user.name -   6D0: File          C:\myFile.mpb

If I run New-SCSMManagementPackBundle again, same error msg appears. If I kill the process, that mean closing powershell_ise, I can bundle the file again. I don't want to close powershell_ise each time, any suggestion?






Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>