使用Powershell脚本访问Sharepoint用户配置文件属性
以下脚本将显示Sharepoint 2007上用户的所有UserProfile属性:使用Powershell脚本访问Sharepoint用户配置文件属性,sharepoint,powershell,Sharepoint,Powershell,以下脚本将显示Sharepoint 2007上用户的所有UserProfile属性: [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") # Function: Get-Use
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")
# Function: Get-UserProfiles
# Description: return a UserProfileManager object containing all user profiles
# Parameters: SSPName SSPName
#
Function global:Get-UserProfiles($SSPName)
{
$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($SSPName);
$UPManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);
return $UPManager.GetEnumerator();
}
$profiles = Get-UserProfiles("SharedServices");
$profiles | ForEach-Object { $_.GetEnumerator();}
但是,我想做的是能够返回配置文件中特定值的表或csv文件,例如用户名、工作电子邮件、工作电话。我已经尝试将输出管道化到|ft Username、WorkEmail、Workphone
和| select Username、WorkEmail、Workphone
,但这只会返回空白
我觉得我离得很近。我不想用大量的
$\.Item(“property”)
调用替换$\.GetEnumerator()
调用,我觉得我不应该这样做。有什么想法吗?我进一步开发了代码,现在它接受一个逗号分隔的属性列表,并将它们写入一个分隔的文件中
# Outputs a delimited file with specified user profile properties for each user in Sharepoint
# Create array of desired properties
$arProperties = 'UserName','FirstName','LastName','Title','WorkEmail','WorkPhone','Manager','AlternateContact','RoleDescription','PictureURL';
# Specify output file
$outfile = 'UserProfiles.csv';
#Specify delimiter character (i.e. not one that might appear in your user profile data)
$delim = '^';
# Specify Shared Service Provider that contains the user profiles.
$SSP = "SharedServices";
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")
# Function: Get-UserProfiles
# Description: return a UserProfileManager object containing all user profiles
# Parameters: SSPName SSPName
#
Function global:Get-UserProfiles($SSPName)
{
$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($SSPName);
$UPManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);
return $UPManager.GetEnumerator();
}
$profiles = Get-UserProfiles($SSP);
#Initialise Output file with headings
$header = [string]::join($delim,$arProperties);
Write-Output $header | Out-File $outfile
#Output the specified properties for each
$profiles | ForEach-Object {
foreach($p in $arProperties){
# Get the property name and add it to a new array, which will be used to construct the result string
$arProfileProps += $_.Item($p);
}
$results = [string]::join($delim,$arProfileProps);
# Get rid of any newlines that may be in there.
$CleanResults = $results.Replace("`n",'');
Write-Output $CleanResults
Remove-Variable -Name arProfileProps
} | Out-File -Append $outfile
这让我更接近了。我仍然非常喜欢一个脚本,它可以遍历所有概要文件属性,并将它们更优雅地放入CSV或XML文件中。现在就这样。否决票?没有解释?这个问题很清楚,甚至提供了一些有用的信息。为什么要投否决票?该问题是否有问题?请(在尝试Fort Table或Select之前)通过管道输出获取成员,并查看您获取的对象是否具有所需的属性,例如
$profiles | Get Member
和$profiles |%{$\u0.GetEnumerator()}| Get Member
。