Powershell's Sharepoint snapin not added while running script

Hi,

     We are trying to run Powershell scripts in TeamCity. Most of our Powershell scripts work with Sharepoint. Problem while running these scripts is Powershell's Sharepoint Snapin is not added. Here is entire log from TeamCity's build.

[14:21:16]: Checking for changes
[14:21:18]: Clearing temporary directory: C:\TeamCity\buildAgent\temp\buildTmp
[14:21:18]: Checkout directory: C:\TeamCity\buildAgent\work\560492675a70b58
[14:21:18]: Updating sources: server side checkout... (1s)
[14:21:20]: Publishing internal artifacts (2s)
[14:21:20]: Starting: C:\TeamCity\buildAgent\work\560492675a70b58\PortalCreation.bat
[14:21:20]: in directory: C:\TeamCity\buildAgent\work\560492675a70b58
[14:21:20]: C:\TeamCity\buildAgent\work\560492675a70b58>powershell.exe ...........\PortalCreation\CreateWebAppandSite.ps1 "........\PortalCreation"
[14:21:21]: Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
[14:21:21]: 2.
[14:21:21]: At ..........\PortalCreation\CreateWebAppandSite.ps1:1 char:13
[14:21:21]: + Add-PSSnapin <<<<  Microsoft.SharePoint.PowerShell
[14:21:21]:     + CategoryInfo          : InvalidArgument: (Microsoft.SharePoint.PowerShel
[14:21:21]:    l:String) [Add-PSSnapin], PSArgumentException
[14:21:21]:     + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
[14:21:21]:    dPSSnapinCommand
[14:21:21]:

[14:21:24]: The term 'Get-SPWebApplication' is not recognized as the name of a cmdlet, func
[14:21:24]: tion, script file, or operable program. Check the spelling of the name, or if a
[14:21:24]:  path was included, verify that the path is correct and try again.
[14:21:24]: At .........\PortalCreation\CreateWebAppandSite.ps1:21 char:39
[14:21:24]: + $webApplication = Get-SPWebApplication <<<<  $siteRoot -ErrorAction SilentlyC
[14:21:24]: ontinue
[14:21:24]:     + CategoryInfo          : ObjectNotFound: (Get-SPWebApplication:String) []
[14:21:24]:    , CommandNotFoundException
[14:21:24]:     + FullyQualifiedErrorId : CommandNotFoundException
[14:21:24]:  
[14:21:24]: Web application does not exist.

[14:21:24]: The term 'Get-SPManagedAccount' is not recognized as the name of a cmdlet, func
[14:21:24]: tion, script file, or operable program. Check the spelling of the name, or if a
[14:21:24]:  path was included, verify that the path is correct and try again.
[14:21:24]: At .........\PortalCreation\CreateWebAppandSite.ps1:36 char:42
[14:21:24]: +     $accountExists = Get-SPManagedAccount <<<<  -Identity $ApplicationPoolAcc
[14:21:24]: ount
[14:21:24]:     + CategoryInfo          : ObjectNotFound: (Get-SPManagedAccount:String) []
[14:21:24]:    , CommandNotFoundException
[14:21:24]:     + FullyQualifiedErrorId : CommandNotFoundException
[14:21:24]: Incorrect Managed Account settings
[14:21:24]:

[14:21:24]: The term 'Get-SPWebApplication' is not recognized as the name of a cmdlet, func
[14:21:24]: tion, script file, or operable program. Check the spelling of the name, or if a
[14:21:24]:  path was included, verify that the path is correct and try again.
[14:21:24]: At ..........\PortalCreation\CreateWebAppandSite.ps1:58 char:46
[14:21:24]: + $webApplicationCreated = Get-SPWebApplication <<<<  $siteRoot
[14:21:24]:     + CategoryInfo          : ObjectNotFound: (Get-SPWebApplication:String) []
[14:21:24]:    , CommandNotFoundException
[14:21:24]:     + FullyQualifiedErrorId : CommandNotFoundException
[14:21:24]:  
[14:21:24]: Process exited with code 0
[14:21:24]: Publishing internal artifacts
[14:21:24]: Build finished

We tried adding snapin through User Profile. But still ended up with same problem.

Could we get some help regarding this ?

Regards,

Madhura Bhatawadekar

Please sign in to leave a comment.