Try_Catch_Finally w/PowerShell and Sharepoint

I want to fail a Sharepoint build running from Powershell and cannot find a way to capture the error.
Try
{

New-SPSite -Url

$SiteURL -OwnerAlias $OwnerAlias -SecondaryOwnerAlias $env:USERDOMAIN\$env:USERNAME -ContentDatabase $database -Description $SiteColDescription -Name $SiteCollName -Language $LCID -Template $Template | Out-Null


}
Catch
{
[system.exception]
ExitWithCode -exitcode 999
}

OR the Try/Catch:

Catch
{
[Microsoft.Sharepoint.PowerShell.SPCmdletNewSite]
ExitWithCode -exitcode 999
}

Replacing custom exit routine (ExitWithCode) with Exit 999 has no impact.

All generate the following error and then continue with the build.

New-SPSite : User cannot be found.
[01:18:40]: At C:\BuildAgent\work\5f76eec6b7e27f8\PC\AutoSPDeploy\AutoSPDeploy\AutoSPDeploy
[01:18:40]: erFunctions.ps1:898 char:16
[01:18:40]: +                     New-SPSite <<<<  -Url $SiteURL -OwnerAlias $OwnerAlias -S
[01:18:40]: econdaryOwnerAlias $env:USERDOMAIN\$env:USERNAME -ContentDatabase $database -De
[01:18:40]: scription $SiteColDescription -Name $SiteCollName -Language $LCID -Template $Te
[01:18:40]: mplate | Out-Null
[01:18:40]: + CategoryInfo          : InvalidData: (Microsoft.Share...SPCmdletNewSite:
[01:18:40]: SPCmdletNewSite) [New-SPSite], SPException
[01:18:40]: + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletNewSite

Any suggestions appreciated.
2 comments
Comment actions Permalink

Eric,

Do you have the same issue if you run the script from console?

If tyes, then this is better to ask in PowerShell-related forums.

0
Comment actions Permalink

Yegor,
Good point.
I assume the problem is the same in PS console.
Was hoping someone else was already using the Powershell runner and had a simple answer.
I will look elsewhere and post a solution when I find it.
Thank you for taking a look at my question,
Eric

0

Please sign in to leave a comment.