SharePoint 2010でカスタム機能を有効にしようとしているときに、PowerShell v2でプログラムによって捕捉、トラップまたは検出されない例外が発生しています。私はエラーが何で、セントラル管理者でそれを修正するのかを知っていますが、PowerShellのデプロイスクリプトがこのエラー状態を特定できないという問題があります。 PowerShellがSharePoint Enable-SPFeature例外をキャッチできません
# This correctly gets the site and feature:
PS C:\> $Error.Clear()
PS C:\> $SiteUrl = 'http://thesite'
PS C:\> $FeatureId = 'D3BF12C5-D342-4F8A-8E86-BB4308699359'
PS C:\> $Site = Get-SPSite | Where { $_.Url -eq $SiteUrl }
PS C:\> $Feature = Get-SPFeature | Where { $_.Id.ToString() -eq $FeatureId }
# But this line produces the error information below it in the console window - in plain color, not red:
PS C:\> $Feature | Enable-SPFeature -url $SiteUrl
Source: Microsoft.Office.Server.UserProfiles
Message: Users cannot override privacy while the property is replicable.
Trace: at Microsoft.Office.Server.UserProfiles.ProfileSubtypeProperty.set_UserOverridePrivacy(Boolean value)
at IHI.Springs.GAC.UserProfile.UserProfilePropertyManager.EnableUserOverridePrivacy(String propertyName)
at IHI.Springs.GAC.EventReceivers.FeatureReceivers.ProfilePropertyFeatureReceiver.FeatureActivated(SPFeatureReceiverProperties properties)
エラーメッセージ
は、上記コンソールに書き込まれますが、プログラムで検出されない:有効-SPFeatureコマンド、$を実行した後? $ trueはエラーです。$ LastExitCodeには何もありません。
try/catchまたはtrapを使用して例外をキャプチャしようとすると失敗します。下の行については、エラーメッセージはコンソールにダンプされますが、「エラーが発生しました!」
try { $Feature | Enable-SPFeature -url $SiteUrl } catch { "Error caught!" }
trap { "Error caught!" } $Feature | Enable-SPFeature -url $SiteUrl
私は何をしてもそのテキストをキャプチャできません。これらの作品のどれも:
エラーメッセージが$のErrorInfoが空で、コンソールに表示されます。
$ErrorInfo = $Feature | Enable-SPFeature -url $SiteUrl 2>&1
$ErrorInfo = $null; $Feature | Enable-SPFeature -url $SiteUrl -ErrorVariable ErrorInfo
エラーメッセージは、コンソールに表示されErrorFile.txtが作成される(予想)が、空である:
$Feature | Enable-SPFeature -url $SiteUrl > c:\temp\ErrorFile.txt
私たちは機能のアクティベーションコードを調べており、これをサーバーで修正する方法はわかっていますが、このエラーをプログラムで検出することはできません。例外はコマンドレットEnable-SPFeatureによってスローされますが、PowerShellはErrorRecordに例外をラップしたり、エラーパイプラインに書き込んだり、有用な処理を行ったりしていません。私はMonad Beta 2が出て以来、たくさんのファンキーなことを見てきたので、かなり広範囲にPowerShellを使ってきましたが、これは私の自信を揺さぶっています。 (私はSharePointに自信がないので、そこに失われたものはありません)。
Powershell + Sharepointエラー処理。ニース! –