Typed Generic Lists in PowerShell

I needed a way to create a typed list in PowerShell to execute the SetManagementServers method(A post on that soon).  It’s pretty simple and I’ve included a couple of the references that I hit while searching it up, I wanted to post the SIMPLEST of the methods I found as there are many.

$MSList = New-Object 'System.Collections.Generic.List[Microsoft.EnterpriseManagement.Administration.ManagementServer]'

 

Load assemblies without Locking DLLs

Working on a series of scripts that referenced a common DLL I ran into an issue that every instance of the script needed to be stopped and the threads all closed before I could update the code in my Custom DLL.

The code below allows a DLL to be loaded into your scripts without locking the file.  In my case this worked perfectly as various scripts were scheduled and multiple instances could be running at once, the file could be upgraded on the fly and current threads would complete with the version the leaded and the next instance runs with the new version.

$DLLBytes = [System.IO.File]::ReadAllBytes(“MyClassLibrary.dll”)
[System.Reflection.Assembly]::Load($DLLBytes)