PowerShell脚本不起作用

时间:2012-02-24 08:17:09

标签: powershell

我尝试在iLoveSharePoint.PowerEventReceiver

中使用以下PowerShell脚本
function ItemAdding
{
    $url = 'http://win-4cc5e89pifo:1234/docs/'
    $web = Get-SPWeb -webUrl $url
    $list = $web.Lists['CodeBehind']

    foreach ($item in $list)
    {
        if ($item.Title -eq $properties.AfterProperties["Title"])
        {
            $properties.Status = [Microsoft.SharePoint.SPEventReceiverStatus]::CancelWithRedirectUrl

            $properties.RedirectUrl = [Microsoft.SharePoint.Utilities.SPUrlUtility]::CombineUrl($properties.Web.Url,"/SitePages/step1.aspx?p=1")

            break
        }   
    }
}

哪里出错?

2 个答案:

答案 0 :(得分:0)

-webUrl Cmdlet似乎没有命名参数Get-SPWeb

尝试

$web = Get-SPWeb $url
而是在你的脚本中

同时检查$web是否为空。

答案 1 :(得分:0)

试试这个 CombineUrl($web.Url,

$httpContext.Response.Redirect("somewhere/to/go",$true);
相关问题