简体   繁体   English

PowerShell-SharePoint 2010-无法找到类型Microsoft.SharePoint

[英]PowerShell - SharePoint 2010 - Unable to find type Microsoft.SharePoint

(NOTE: the following problem after appeared after the production server in question underwent system hardening): (注意:相关生产服务器经过系统加固后出现以下问题):

I have a PowerShell module that contains the following line: 我有一个包含以下行的PowerShell模块:

[OutputType([Microsoft.SharePoint.Publishing.PublishingPage])] [输出类型([Microsoft.SharePoint.Publishing.PublishingPage])]

When I open a PowerShell console running as Administrator (as well as being logged in to the server as a sys admin), I get the following: 当我打开以管理员身份运行(以及以sys admin身份登录到服务器)运行的PowerShell控制台时,得到以下信息:

Unable to find type [Microsoft.SharePoint.Publishing.PublishingPage]: make sure that the assembly containing this type is loaded. 找不到类型[Microsoft.SharePoint.Publishing.PublishingPage]:确保已加载包含此类型的程序集。

I am able to "force" the Microsoft.SharePoint.Publishing DLL to load with both LoadWithPartialName as well as Add-Type, but then I get the same error with regard to Microsoft.SharePoint when I try to execute my module. 我能够“强制” Microsoft.SharePoint.Publishing DLL以同时加载LoadWithPartialName和Add-Type,但是当我尝试执行模块时,会遇到关于Microsoft.SharePoint的相同错误。

Both DLLs are definitely in the GAC (version 14.0.0.0 as this is SharePoint 2010) and when I view permissions on the GAC, the permissions are sufficient. 两个DLL肯定都在GAC中(版本14.0.0.0,因为这是SharePoint 2010),当我查看GAC的权限时,这些权限就足够了。

As stated previously, the module executed fine previously, and the "Unable to find" error only started occurring after the server in question underwent some system hardening by a third-party. 如前所述,该模块以前执行得很好,并且仅在所讨论的服务器经过第三方的一些系统强化后,才开始出现“无法找到”错误。 I have tried to investigate the issue from a permissions and group policy standpoint, but so far I do not have any leads. 我已经尝试从权限和组策略的角度调查此问题,但是到目前为止,我没有任何线索。

I am able to somewhat reproduce the error in my dev environment if I completely trash the permissions on my GAC, but this does not truly reflect the situation in production, as the permissions in production appear to be more than sufficient for being able to "see" a DLL in the GAC. 如果完全放弃我的GAC上的权限,我可以在开发环境中重现该错误,但这并不能真正反映生产环境,因为生产环境中的权限似乎足以“查看” “ GAC中的DLL。

Any help would be greatly appreciated. 任何帮助将不胜感激。

You might have better luck with [Microsoft.SharePoint.Publishing.PublishingPage] ;-) 使用[Microsoft.SharePoint.Publishing.PublishingPage] ;-)可能会更好

That said, for types that are not part of the BCL, you should use a string instead of a type literal. 也就是说,对于不属于BCL的类型,应使用字符串而不是类型文字。 This allows the module to be loaded - at least - on a machine without sharepoint. 这允许将模块至少加载到没有共享点的计算机上。 That would look like: 看起来像:

[outputtype("Microsoft.SharePoint.Publishing.PublishingPage")]

As far as powershell is concerned, the constraint is the same. 就powershell而言,约束是相同的。

In the end, right-clicking on the PowerShell icon and selecting "Import System Modules" was the solution. 最后,右键单击PowerShell图标并选择“导入系统模块”是解决方案。

When I changed my OutputType to use quotes instead of brackets, I then received an error that Get-SPSite was not recognized as a cmdlet (selecting "Import System Modules" resolved this error.) I then went back to using brackets for the OutputType and confirmed that "Import System Modules" was all that I needed. 当我将OutputType更改为使用引号而不是方括号时,我收到一个错误,即Get-SPSite无法识别为cmdlet(选择“导入系统模块”解决了此错误。)然后,我回到对OutputType使用方括号和确认“导入系统模块”是我所需要的。

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

相关问题 使用Powershell连接到sharepoint oniline:找不到类型为Microsoft.SharePoint.Client.ClientContext的适当构造函数 - connecting to sharepoint oniline using Powershell : Cannot find an appropriate constructor for type Microsoft.SharePoint.Client.ClientContext 无法将值“ w”转换为键入“ Microsoft.SharePoint.SPFeatureScope” powershell - Cannot convert value “w” to type “Microsoft.SharePoint.SPFeatureScope” powershell 使用PowerShell配置SharePoint 2010 UPS - Configure SharePoint 2010 UPS with PowerShell 无法使用 PowerShell 访问 SharePoint - Unable to Access SharePoint using PowerShell SharePoint 2010 PowerShell命令获取必需的参数 - SharePoint 2010 PowerShell command get required parameters C#远程Powershell SharePoint 2010 - C# Remote Powershell SharePoint 2010 在安装Sharepoint 2010之前先卸载PowerShell 1.0 - Uninstalling PowerShell 1.0 before installing Sharepoint 2010 使用Powershell连接到Microsoft Access DB / SharePoint列表 - Connect to Microsoft Access DB/SharePoint List with Powershell 为Microsoft SharePoint添加PowerShell管理单元时出错 - Error when adding powerShell snapins for Microsoft SharePoint 使用PowerShell将用户添加到SharePoint 2010组 - Add user to SharePoint 2010 group using powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM