首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在RunWithElevatedPrivileges内时,foreach continue不起作用

在RunWithElevatedPrivileges内时,foreach continue不起作用
EN

Stack Overflow用户
提问于 2018-05-31 18:38:27
回答 1查看 331关注 0票数 0

下面的代码在出现错误时继续执行,

代码语言:javascript
复制
    foreach($url in Get-Content $urlsDir) 
    {
        try
        {
            // do something
            // declare X
        }
        catch
        {
            // write host or soemthing with exception
            continue
        }
        finally
        {
            // dispose X
        }
    }

但是当我把这段代码放到RunWithElevatedPrivileges中时,它会在第一次出错时完全停止,不会继续执行,

代码语言:javascript
复制
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({ 
        # Iterate through all webs in a text file
        foreach($url in Get-Content $urlsDir) 
        {
            try
            {
                // do something
                // declare X
            }
            catch
            {
                // write host or soemthing with exception
                continue
            }
            finally
            {
                // dispose X
            }
        }
  });
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50622342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档