Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unload assemblies [duplicate]

I'm trying to create a script that will output a list of Fully Qualified Names for DLLs. The script I currently have works fine when it comes to outputting the data I want.

The problem is that this locks the file. So if I want to delete one of the files that I loaded in my session I get the following message:

The action can't be completed because the file is open in Windows PowerShell.

What do I change to have PowerShell release the lock on the file?

I usually run PowerShell script from the internal console in Visual Studio Code, but the problem also exists when I run it directly from PowerShell.

Enter-PSSession -ComputerName $env:computername
Get-ChildItem -Path $input -Filter '*.dll' | ForEach-Object {
    $assembly = [System.Reflection.Assembly]::LoadFrom($_.FullName)
    Write-Host $assembly.FullName
}
Exit-PSSession
like image 618
Chrono Avatar asked Sep 10 '25 13:09

Chrono


1 Answers

You can use in-memory assembly:

Get-ChildItem -Path $input -Filter '*.dll' | ForEach-Object {
    $assembly = [System.Reflection.Assembly]::Load([IO.File]::ReadAllBytes($_.FullName))
    Write-Host $assembly.FullName
}
like image 114
Paweł Dyl Avatar answered Sep 13 '25 07:09

Paweł Dyl