Вопрос

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.

SPWeb.SiteUserInfoList property

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top