简体   繁体   English

如何将程序集[Systems.Collections.Specialized.StringCollection]加载到Powershell中

[英]How to load assembly [Systems.Collections.Specialized.StringCollection] into Powershell

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]: 我正在尝试使用[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. 该文档说, Add-Type将接受.dll的位置。 Looking at the documentation for the StringCollection Class the .dll I want is System.dll . 查看StringCollection类的文档,我想要的.dll是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? 我需要一个特殊的.dll文件吗?

To expand on the comment from @PetSerAl: You have an s after System that shouldn't be there. 要扩展来自@PetSerAl的评论,请执行以下操作:在System之后有一个s不应存在​​。 Do this instead 改为这样做

$newDBFiles = new-object System.Collections.Specialized.StringCollection;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM