我有一個自定義的PowerShell腳本,它接受一些參數作爲輸入。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
感謝您幫助。正如我在編輯中所說的,我堅持使用PS V2。我實際上可以訪問腳本,但我無法硬編碼參數,它們必須來自Visual Studio宏(請看我的anwser)。 –