【问题标题】:Loop trough multiple SharePoint site collections循环访问多个 SharePoint 网站集
【发布时间】:2020-04-01 20:56:57
【问题描述】:

目前我有这个脚本:

$SiteURL="https://contoso.sharepoint.com/sites/contoso"
$UserID="j.doe@contoso.nl"

#Get Credentials to connect
$Cred = Get-Credential

#Connect to SharePoint Online Admin Site
Connect-SPOService -Url $AdminSiteURL -Credential $cred

#sharepoint online powershell remove user permissions from site collection
Get-SPOUser -Site $SiteURL -LoginName $UserID

但我有多个网站集,它需要在其中找到该用户:

https://contoso.sharepoint.com/sites/Projecten
https://contoso.sharepoint.com/sites/PFO

如何使用for 循环执行此操作,以便在每个网站集中找到用户?

【问题讨论】:

    标签: powershell sharepoint


    【解决方案1】:

    已经想通了:

    $UserID="j.doe@contoso.nl"
    
    $sitecollectios = @("https://contoso.sharepoint.com/sites/Extranet","https://contoso.sharepoint.com/sites/contoso","https://contoso.sharepoint.com/sites/Projecten","https://contoso.sharepoint.com/sites/PFO","https://contoso.sharepoint.com/sites/beheer","https://contoso.sharepoint.com/sites/Intranet")
    
    #Get Credentials to connect
    $Cred = Get-Credential
    
    #Connect to SharePoint Online Admin Site
    
    Connect-SPOService -Url $AdminSiteURL -Credential $cred
    
    foreach ($collectie in $sitecollectios)
    { 
        Get-SPOUser -Site $collectie -LoginName $UserID
    }
    

    【讨论】:

    • 顺便说一句:我建议避免 @(...) 用于数组文字;例如,不要使用 @('a', 'b'),而是使用 'a', 'b'@(...) 不仅是不必要的,它在 PowerShell 版本高达 5.0 中效率低下,而且 - 更重要的是 - 它通过错误地暗示它构造数组而引起概念上的混乱。有关详细信息,请参阅this answer 的底部部分。
    猜你喜欢
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多