I'm having an odd issue with running a PowerShell script as a TeamCity build step, particularly with SqlPs
(though I'm not sure it's specific to SqlPs
).
This one-line script fails in TeamCity:
Import-Module SqlPs
With the following error:
Import-Module : The specified module 'SqlPs' was not loaded because no valid module file was found in any module directory. At C:\TeamCity\buildAgent\temp\buildTmp\powershell2962302231054758126.ps1:13 char:1 + Import-Module SqlPs + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (SqlPs:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands .ImportModuleCommand
I'm pretty sure I have everything configured properly, because if I open PowerShell natively from the CI server that TeamCity is running on, I can run this with no problems.
I can even run the above temp script file that TeamCity generates from within the native PowerShell, and it works just fine.
Further, if I execute Get-Module
from the native PowerShell:
Get-Module -ListAvailable
It will dump several system modules from:
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
Along with the SqlSp modules from:
C:\Program Files\Microsoft SQL Server\110\Tools\PowerShell\Modules
But when I run the same Get-Module
from the TeamCity build, it will only list the system modules -- no SqlSp
module.
I thought it might be an issue with permissions, but when I log in to native PowerShell as the same account that TeamCity uses, I still have no issues.
I also tried selecting x86 instead of x64 for bitness just to rule that out, and it fails either way.
Putting "SqlPs"
in quotes also didn't help.