【发布时间】:2014-08-25 22:50:57
【问题描述】:
我想在 SharePoint 中为应用程序开发配置 高度信任的应用程序,为此,我首先需要在 powershell 编辑器中插入一些命令,例如:
$publicCertPath = "C:\Certs\HighTrustSampleCert.cer"
$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($publicCertPath)
我在 Windows Server 2012 R2 上使用 Windows PowerShell,其中包括 Windows PowerShell 4,默认情况下包括 new-object cmd-let...我不明白,为什么我的操作系统无法识别该命令。 .. 我不会停止出现以下错误:New-Object:术语“New-Object”未被识别为 cmdlet 的名称。
当我打开 powerShell 时,我得到了这个:
*选择:
“Select-Object”一词未被识别为 cmdlet 的名称, 函数、脚本文件或可运行的程序。检查拼写 名称,或者如果包含路径,请验证路径是否正确并 再试一次。在 C:\Program Files\Common Files\Microsoft Shared\Web 服务器扩展\15\CONFIG\POWERSHELL\Registration\SharePoint.ps1:1 字符:16 + $ver = $主机 |选择版本 +~~~~~~ + CategoryInfo : ObjectNotFound: (Select-Object:String) [], Comm ndNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Set-location : 术语“Set-location”未被识别为 cmdlet 的名称, 函数、脚本文件或可运行的程序。检查拼写 名称,或者如果包含路径,请验证路径是否正确并 在 C:\Program Files\Common Files\Microsoft Shared\Web Server 再试一次 Extensions\15\CONFIG\POWERSHELL\Registration\SharePoint.ps1:4 char:1 + 设置位置 $home +~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Set-location:String) [], Command dNotFoundException + FullyQualifiedErrorId : CommandNotFoundException*
直到今天我都认为这是正常的......它与错误有什么关系吗?这是洞(新对象)异常堆栈:
New-Object :“New-Object”一词未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查拼写 的名称,或者如果包含路径,请验证该路径是 正确并重试。在行:1 字符:16 + $certificate = 新对象 System.Security.Cryptography.X509Certificates.X509Cert ... + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (New-Object:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
ps:我想提一下,当我使用 enter-psSession 并远程工作时,命令 new-object 被识别,但不再识别共享点命令(如 Get-SPAuthenticationRealm)......而且好像有问题与操作系统有关。
【问题讨论】:
-
您已经尝试过 Get-Command 和/或 Get-Help 来查看它是否被识别,对吧。得到这个错误很奇怪,默认情况下应该可用。
-
New-Objectcmdlet 自 PowerShell 1.0 起可用。它也由Microsoft.PowerShell.Utility模块导出,因此如果您的 PowerShell 会话中没有加载它,则可能会触发类似的错误。Get-Module的结果列表中是否包含该模块? -
@KarouiHaythem:是的,当然。 PowerShell 是模块化的。某些 cmdlet(如
New-Object)仅在加载了实现它们的模块时才可用。New-Object,特别是由Microsoft.PowerShell.Utility模块提供。您可以通过运行Get-Modulecmdlet 来验证此模块是否已加载到您的会话中。这将为您提供已加载模块的列表,Microsoft.PowerShell.Utility应该在列表中。这应该可以确认您是否有New-Object可用。 -
运行
Get-Module -ListAvailable' to get the list of PowerShell modules available for loading. This should includeMicrosoft.PowerShell.Utility. If it's in the list, you can just runImport-Module Microsoft.PowerShell.Utility`来加载它。顺便说一下,这个模块是 PowerShell 的核心模块之一,所以默认会话应该包括它们。如果这只是一个常规的 PowerShell 会话,您可能需要尝试修复您的 PowerShell 安装。 -
@KarouiHaythem:谢谢。我不确定我是否应该像您所做的工作一样得到赞誉,但无论如何我已经发布了我的答案以供将来参考。您可能希望添加最终解决问题的方式。谢谢。
标签: powershell sharepoint-2013 windows-server-2012