I semi understand what I'm asking and have tried to research this as best as I'm able.
I'm trying to use an object of type [Systems.Collections.Specialized.StringCollection]:
$newDBFiles = new-object Systems.Collections.Specialized.StringCollection;
I get the error:
new-object : Cannot find type [Systems.Collections.Specialized.StringCollection]: make sure the assembly containing this type is loaded.
At line:1 char:15
+ $newDBFiles = new-object Systems.Collections.Specialized.StringCollection;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
I've tried loading the assembly a few different ways without success:
[System.Reflection.Assembly]::LoadWithPartialName("System.Collections.Specialized") | Out-Null;
add-type -AssemblyName systems;
add-type -AssemblyName systems.collections;
The documentation says that Add-Type
will accept a location to the .dll. Looking at the documentation for the StringCollection Class the .dll I want is System.dll
. That sounds like it should already be present on my system.
When I look at the assemblies already loaded, I see this one, which appears to me be correct:
[appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname
System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
There's numerous posts about using the type but I couldn't find any on how to load the specific assembly. Do I need a special .dll file?
To expand on the comment from @PetSerAl: You have an s after System
that shouldn't be there. Do this instead
$newDBFiles = new-object System.Collections.Specialized.StringCollection;