Lists[“User Information List”] is null
-
11-10-2020 - |
문제
I'm trying to export groups from my site and I used this script.
$siteUrl="http://mysite"
$groupName="BWS Team"
$Output = @("GroupName|Name|Login|Email|Department|Title")
$web = Get-SPWeb $siteUrl
$site = $web.Site
$rootWeb = $site.RootWeb
$UserList = $rootWeb.Lists["User Information List"]
$web.SiteGroups[$groupName].Users|%{$user = $UserList.GetItemById($_.ID)
if($user -ne $null)
{
$JobTitle = $user["JobTitle"]
$Department = $user["Department"]
}
$Output += ($groupName+"|"+$_.Name+"|"+$_.UserLogin+"|"+$_.Email+"|"+$Department +"|"+$JobTitle)
}
$rootWeb.Dispose()
$web.Dispose()
$site.Dispose()
$Output > "D:\MembersExport.csv"
You cannot call a method on a null-valued expression.
At line:8 char:37
+ $web.SiteGroups[$groupName].Users|%{$user = $UserList.GetItemById($_.ID)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
해결책
To access the UserInformationList you need to directly call for it instead of using <SPWeb>.Lists[<listTitle>]
like:
$siteUrl="http://mysite"
$web = Get-SPWeb $siteUrl
$userList = $web.SiteUserInfoList;
다른 팁
I ran the same script and it works well. if $UserList
is null, that may mean the Title of the User Information List may have been modified. You can confirm that by browsing this Url: http://yoursite/_catalogs/users/simple.aspx
. Alternatively, as suggested by @garglblarg, you can use SPWeb.SiteUserInfoList
directly.
제휴하지 않습니다 sharepoint.stackexchange