Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :

$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.

When i open powerShell i get this :

*select :

The term 'Select-Object' is not recognized as the name of a cmdlet, function, script file, or operable program. 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 | 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. 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*

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. 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

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 ... And it's like there is a problem related to the operating system.

like image 767
Haithem KAROUI Avatar asked Jul 04 '14 15:07

Haithem KAROUI


People also ask

How do you fix is not recognized as the name of a cmdlet?

By default, you have to install modules in the exact order to use them. If that module is missing, corrupt, or got moved, it throws up the error, “the term is not recognized as the name of a cmdlet.” You can use “get-module” in PowerShell to see if the module is present and correct.

What is new object in PowerShell?

New-Object creates the object and sets each property value and invokes each method in the order that they appear in the hash table. If the new object is derived from the PSObject class, and you specify a property that does not exist on the object, New-Object adds the specified property to the object as a NoteProperty.

What is not recognized as the name of a cmdlet window?

The first thing you should do when you see the “term is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again” error message is to check the spelling of the cmdlet or function name.

How do you get the help for a cmdlet to show up in another Windows?

Description. The Get-Help cmdlet displays information about PowerShell concepts and commands, including cmdlets, functions, Common Information Model (CIM) commands, workflows, providers, aliases, and scripts. To get help for a PowerShell cmdlet, type Get-Help followed by the cmdlet name, such as: Get-Help Get-Process .


1 Answers

It appears that your PowerShell installation is corrupted and needs to be repaired. 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.

like image 103
PeterK Avatar answered Oct 04 '22 23:10

PeterK