Powershell 和 System.Security.Cryptography.X509Certificates.X509Certificate2
当我运行 system.security 命名空间时,出现此错误。这就是我正在追求的
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")
New-Object: Cannot find type [System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")]: make sure the assembly containing this type is loaded.
At line:1 char:19
+ $cert = New-Object <<<<
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand**
我做错了什么?
i'm getting this error when i run the system.security namespace. This is what i am running after
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")
New-Object: Cannot find type [System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")]: make sure the assembly containing this type is loaded.
At line:1 char:19
+ $cert = New-Object <<<<
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand**
What am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试运行此命令以查看是否已加载 System.dll(默认情况下):
如果已加载,则此命令应显示
X509Certificate2
类型:如果未加载 System.dll (这会很奇怪)尝试加载它:
请参阅:http://technet.microsoft.com/en-us/library/hh849914.aspx
Try running this to see if you have the System.dll loaded (should be by default):
If it is loaded then this command should show the
X509Certificate2
type:If the System.dll isn't loaded (which would be odd) try loading it:
See: http://technet.microsoft.com/en-us/library/hh849914.aspx
仅供参考...我收到错误:
使用时:
但是,我在脚本中早期创建集合时没有错误:
为了使错误消失,我必须在早期的某个时刻包含以下内容:
FYI ... I got error:
when using:
However, I had no error creating the collection earlier on in my script:
To make the error go away I had to include the following at some point earlier on:
我已经解决了我的问题。这很容易:
cd\ 是必要的
I've solved my problem. It's easily:
cd\ is necessary
我在 ISE 中遇到了这个问题(但似乎也适用于普通命令窗口),并且似乎使用自动完成功能会自动为您要查找的内容添加类型。如果您启动一个新实例并运行:
它将不会返回
System.Security
,但如果您随后键入此命令并让智能感知执行其操作:您可以再次运行此命令:
然后它将返回 <代码>系统.安全。因此,这就是为什么您可以编写一个运行良好的脚本,然后稍后重新访问它,但它却损坏了。使用智能感知并不能修复你的脚本,而是你必须添加这一行:
或者任何没有自动添加的库(它似乎需要 dll 文件名,例如
C:\Program Files (x86)\Reference程序集\Microsoft\Framework\.NETFramework\v4.6.1\System.Security.dll
)。我非常确定 IseSteroids(付费 ISE 插件)可以检测到这一点,也许其他的也可以。
I ran into this in the ISE (but seems to apply to the normal command window too) and it seems that using autocomplete will automatically
Add-Type
for whatever you're looking for. If you start a new instance and run:it will not return
System.Security
, but if you then type this and let intellisense do its thing:You can then run this again:
And it will then return
System.Security
. So this is why you can write a script that works fine, and then revisit it later and it's broken. Using intellisense doesn't fix your script though, instead you have to add this line:Or whatever library is not getting auto-added (it seems to need the dll filename, e.g.
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Security.dll
).I'm pretty sure IseSteroids (a paid ISE add-in) can detect this, maybe others as well.