2010-07-01 2 views
4

다음 스크립트는 셰어 포인트 2007 사용자에 대한 모든 사용자 프로필 속성을 뱉어 그러나PowerShell 스크립트에 액세스 셰어 사용자 프로필 속성

[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 파일을 반환 할 수 있습니다 수행 할 작업 프로필의 특정 값 (예 : 사용자 이름, WorkEmail, WorkPhone. 나는 출력을 |ft Username, WorkEmail, Workphone| select Username, WorkEmail, WorkPhone으로 파이핑했으나 공백만을 반환합니다.

나는 너무 가깝다고 느낍니다. 나는 $_.Item("property") 호출을 많이 사용하여 $_.GetEnumerator() 호출을 대체하고 싶지 않고 그렇게해야한다고 생각하지 않습니다. 어떤 아이디어?

+0

A 투표? 설명없이? 질문은 분명하고 심지어 유용한 정보를 제공합니다. 왜 그것을 downvote? 질문에 문제가 있습니까? – dunxd

+0

+1 downvote를 취소하려면 – Ryan

+0

Get-Member로 출력 (Fort-Table 또는 Select를 시도하기 전에)을 파이프하고 기대하는 속성을 가진 객체를 가져 오는 지 확인하십시오. '$ profiles | get-member'와'$ profiles | % {$ _. GetEnumerator()} | get-member'. –

답변

3

필자는 이제 코드를 개발하여 쉼표로 구분 된 속성 목록을 받아들이고 구분 된 파일에 씁니다.

# 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 파일에보다 우아하게 넣는 스크립트를 정말 좋아할 것입니다. 이것은 현재 할 것입니다.

관련 문제