gpt4 book ai didi

sharepoint - 使用 Powershell 脚本访问 Sharepoint 用户配置文件属性

转载 作者:行者123 更新时间:2023-12-04 18:31:35 26 4
gpt4 key购买 nike

以下脚本为 Sharepoint 2007 上的用户输出所有 UserProfile 属性:

[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但这只是返回空白。

我觉得我很亲近。我不想更换 $_.GetEnumerator()电话很多 $_.Item("property")打电话,我觉得我不应该这样做。有任何想法吗?

最佳答案

我进一步开发了代码,以便它现在接受逗号分隔的属性列表并将它们写入分隔文件。

# 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 文件中。这暂时就可以了。

关于sharepoint - 使用 Powershell 脚本访问 Sharepoint 用户配置文件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3157038/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com