Powershell-SharePoint Online-尝试将用户添加到自定义列表列类型“人员"和“组" [英] Powershell - SharePoint Online - Trying to add a user to a custom list column type People and Group

查看:138
本文介绍了Powershell-SharePoint Online-尝试将用户添加到自定义列表列类型“人员"和“组"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Powershell,可以扫描所有站点并找到这些站点的所有者,我想将该站点和所有者添加到自定义列表中.我似乎无法获得将用户添加到自定义列表中的列的语法.网站所有者 列确实允许多项选择.任何帮助将不胜感激.我的脚本如下:

I have a powershell that scans all sites and finds the owners of those sites and I want to add the site and the owners to a custom list.  I can not seem to be able to get the syntax of adding users to a column in my custom list.  The SiteOwners column does allow for multiple selections.  Any help would be appreciated.  My script is below:

$ Sites_List = $ global:AuditSiteClientContext.Web.Lists.GetByTitle($ global:SitesList);
    $ itemCreateInfo =新对象Microsoft.SharePoint.Client.ListItemCreationInformation;
    $ newItem = $ Sites_List.AddItem($ itemCreateInfo);
    $ newItem ["Title"] ="Site";
    $ newItem [" Audit_URL] = $ Site_URL;
    $ newItem ["SiteAccessible"] = $ Accessible;

    #现在获取所有者并添加此站点的所有者
    #获取所有者组名称
    $ ownerGroup = get-spoSitegroup -site $ Site_URL |其中{$ _.title -like"* Owners"}
    $ ownertitle = $ ownerGroup.title
   写主机所有者组被命名为> $ ownertitle> " -forecolorcolor青色
    $ Owners = Get-SPOUser -Site $ Site_URL -Group $ ownertitle |选择登录名|其中{$ _.LoginName -like的"* madisoncollege.edu""}
    #[Microsoft.SharePoint.SPFieldUserValueCollection] $ lotsofpeople =新对象Microsoft.SharePoint.SPFieldUserValueCollection  

    #遍历组中的所有用户,并将其添加到newItem ["Site Owners"]字段
    foreach($ Owner中的$ user)
    {
        写主机"所有者:" $ user.LoginName
    }
    #更新ListItem
    $ newItem.Update();

$Sites_List = $global:AuditSiteClientContext.Web.Lists.GetByTitle($global:SitesList);
    $itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation;
    $newItem = $Sites_List.AddItem($itemCreateInfo);
    $newItem["Title"] = "Site";
    $newItem["Audit_URL"] = $Site_URL;
    $newItem["SiteAccessible"] = $Accessible;

    # Now Get the owners and add the owners of this site
    #get the owner group name
    $ownerGroup = get-spoSitegroup -site $Site_URL | where {$_.title -like "*Owners"}
    $ownertitle = $ownerGroup.title
    Write-host "Owner Group is named > $ownertitle > " -foregroundcolor cyan
    $Owners = Get-SPOUser -Site $Site_URL -Group $ownertitle | Select LoginName | where {$_.LoginName -like "*madisoncollege.edu"}
    #[Microsoft.SharePoint.SPFieldUserValueCollection]$lotsofpeople = New-Object Microsoft.SharePoint.SPFieldUserValueCollection            

    # Loop through all users in group and add them to the newItem["Site Owners"] field
    foreach ($user in $Owners)
    {
        Write-host "Owner: " $user.LoginName
    }
    # Update the ListItem
    $newItem.Update();

推荐答案

以下PowerShell脚本代码段供您参考:

The following PowerShell script snippet for your reference:


userName =域\用户"
userName = "domain\user"


spuser =确保用户
spuser = EnsureUser


这篇关于Powershell-SharePoint Online-尝试将用户添加到自定义列表列类型“人员"和“组"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆