1

I want to configure a 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 cmdlet. I don't understand though, why doesn't my system recognize that command. Each time I am getting the following error :

New-Object : The term 'New-Object' is not recognized as the name of a cmdlet.

Every time I open PowerShell it displays me the following error :

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 whole (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

Can anyone help me please?

ps: I want to mention too that when I used enter-pssession and worked remotely, the command new-object was recognized but SharePoint commands (like Get-SPAuthenticationRealm) were no longer recognized. This is really confusing.

1
  • Sounds like it could be permission settings. As the command "New-Object" is loaded when you run a remote session. That would also explain why Get-SPAuthenticationRealm does not work, because the user does not have permission to execute it. What is your Get-ExecutionPolicy settings?
    – Robban1980
    Jul 7, 2014 at 9:02

2 Answers 2

1

We can find the answer in this post.

The "module" folder was empty and we needed to refill the modules list within it. This way we have all the commands available for loading.

We can see the list by typing Get-Module -ListAvailable. This should include Microsoft.PowerShell.Utility.

0

have you try to add Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue and run with user that has Admin right then run your code again

2
  • Yeah , but this will not remove the problem... just hiding it .... Jul 7, 2014 at 7:10
  • -ErrorAction above will disregard an error if Add-PSSnapin has been added previously
    – Supermode
    Jul 7, 2014 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.