简体   繁体   English

New-Object:术语New-Object不被识别为cmdlet的名称

[英]New-Object : The term New-Object is not recognized as the name of a cmdlet

I want to configure high trusted app for app dev in SharePoint, and to do so, i need first to insert some commands in the powershell editor like : 我想为SharePoint中的app dev配置高可信应用程序,为此,我首先需要在powershell编辑器中插入一些命令,如:

$publicCertPath = "C:\Certs\HighTrustSampleCert.cer" 
$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($publicCertPath)

I am using windows PowerShell on Windows Server 2012 R2 which includes Windows PowerShell 4 that includes by default the new-object cmd-let... I don't understand though, why doesn't my operating system recognize that command ... I don't stop having the following error : New-Object : The term 'New-Object' is not recognized as the name of a cmdlet. 我在Windows Server 2012 R2上使用Windows PowerShell,其中包括Windows PowerShell 4,默认情况下包含新对象cmd-let ...我不明白,为什么我的操作系统不识别该命令...我不要停止出现以下错误:New-Object:术语“New-Object”不会被识别为cmdlet的名称。

When i open powerShell i get this : 当我打开powerShell时,我得到了这个:

*select : *选择 :

The term 'Select-Object' is not recognized as the name of a cmdlet, function, script file, or operable program. 术语“选择对象”不被识别为cmdlet,函数,脚本文件或可操作程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 At C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\15\\CONFIG\\POWERSHELL\\Registration\\SharePoint.ps1:1 char:16 + $ver = $host | 在C:\\ Program Files \\ Common Files \\ Microsoft Shared \\ Web Server Extensions \\ 15 \\ CONFIG \\ POWERSHELL \\ Registration \\ SharePoint.ps1:1 char:16 + $ ver = $ host | select version + ~~~~~~ + CategoryInfo : ObjectNotFound: (Select-Object:String) [], Comma ndNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Set-location : The term 'Set-location' is not recognized as the name of a cmdlet, function, script file, or operable program. select version + ~~~~~~ + CategoryInfo:ObjectNotFound:(Select-Object:String)[],逗号ndNotFoundException + FullyQualifiedErrorId:CommandNotFoundException设置位置:术语“设置位置”不被识别为cmdlet的名称,功能,脚本文件或可操作程序。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again At C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\15\\CONFIG\\POWERSHELL\\Registration\\SharePoint.ps1:4 char:1 + Set-location $home + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Set-location:String) [], Comman dNotFoundException + FullyQualifiedErrorId : CommandNotFoundException* 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后再次尝试在C:\\ Program Files \\ Common Files \\ Microsoft Shared \\ Web Server Extensions \\ 15 \\ CONFIG \\ POWERSHELL \\ Registration \\ SharePoint。 ps1:4 char:1 + Set-location $ home + ~~~~~~~~~~~~ + CategoryInfo:ObjectNotFound:(Set-location:String)[],Comman dNotFoundException + FullyQualifiedErrorId:CommandNotFoundException *

I thought that was normal until today... does it have any relation with the error? 我认为这是正常的,直到今天......它与错误有任何关系吗? And here is the hole (new-object) exception stack: 这是洞(新对象)异常堆栈:

New-Object : The term 'New-Object' is not recognized as the name of a cmdlet, function, script file, or operable program. New-Object:术语“New-Object”不被识别为cmdlet,函数,脚本文件或可操作程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 At line:1 char:16 + $certificate = New-Object System.Security.Cryptography.X509Certificates.X509Cert ... + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (New-Object:String) [], CommandN otFoundException + FullyQualifiedErrorId : CommandNotFoundException 在行:1 char:16 + $ certificate = New-Object System.Security.Cryptography.X509Certificates.X509Cert ... + ~~~~~~~~~~ + CategoryInfo:ObjectNotFound:(New-Object:String)[ ],CommandN otFoundException + FullyQualifiedErrorId:CommandNotFoundException

ps: i want to mention that when i used enter-psSession and worked remotely, the command new-object was recognized but sharepoint commands (like Get-SPAuthenticationRealm) were no more recognized ... ps:我想提一下,当我使用enter-psSession并远程工作时,命令new-object被识别,但sharepoint命令(如Get-SPAuthenticationRealm)不再被识别......

It appears that your PowerShell installation is corrupted and needs to be repaired. 您的PowerShell安装似乎已损坏,需要进行修复。 The New-Object cmdlet is exported by the Microsoft.PowerShell.Utility module, which is one of the Core PowerShell modules and should be imported by default on all PowerShell installations. New-Object cmdlet由Microsoft.PowerShell.Utility模块导出,该模块是Core PowerShell模块之一,默认情况下应在所有PowerShell安装中导入。

This can be because the Registry key entry for PSModulesPath is not pre-filled with the default PowerShell Modules path. 这可能是因为PSModulesPath的注册表项条目未预先填充默认的PowerShell模块路径。

$PSModulePath = Get-ItemProperty -Path "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PSModulePath"

$newPSModulePath = $PSModulePath.PSModulePath + ";C:\Windows\System32\WindowsPowerShell\v1.0\Modules"

Set-ItemProperty -Path "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PSModulePath" -value $newPSModulePath

这里没有任何验证,但我推进了Powershell遇到运行时错误导致它破坏其进程的假设。

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

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