我有一个自定义 PowerShell 脚本,它接受一些参数作为输入。
但是,其中一个参数属于在外部程序集中定义的类型。这意味着当我使用 PowerShell.exe 从命令行运行脚本时,程序集不会加载并且脚本会失败。
以下是脚本的相关部分:
[CmdLetBinding()]
param(
[Parameter(Mandatory=$true, Position=0)]
[Microsoft.SharePoint.PowerShell.SPWebPipeBind]$Web
)
# The SharePoint snapin will load 'Microsoft.SharePoint.PowerShell'
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0
Write-Host "Let's dance"
以及我如何触发脚本(实际上来自 SharePoint 项目的部署后事件):
"%WINDIR%\SysNative\WindowsPowerShell\v1.0\powershell.exe" -file "c:\pathto\fixeditablefields.ps1" "http://myapp"
有没有办法告诉 PowerShell.exe 在运行脚本之前加载程序集?
[编辑]在使用 SharePoint 时,我坚持使用 PowerShell V2