Podemos extraer toda la información que deseemos de la base de datos de perfiles de sharepoint.
Como nuestros amigos de Microsoft lo llaman "sincronización de perfiles" cuando realmente es un volcado de datos, a veces se queda mucha basura y perfiles con sitios creados, que son difíciles de localizar para eliminarlos.
Aunque también podemos crear las que necesitemos y obtenerlas como muestro en el script de ejemplo.
Con este script powershell podemos hacer la tarea de buscar basura y poner orden un poco mas facil.
TRUCO1: Podemos hacer un backup alternativo en excel de las propiedades de los perfiles, con este sistema (descomentar la parte final)
TRUCO2: Con otro Powershell podriamos cargar la información desde un Excel, en lugar de usar el pesado proceso de sicronización.
#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
function GetAllUserProfiles(){
#Get ServiceContext from associated site
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);
#Get UserProfileManager from the My Site Host Site context
$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
$AllProfiles = $ProfileManager.GetEnumerator()
#foreach($profile in $AllProfiles|Where-Object { $_.[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value -match "el filtro que quieras"})
foreach($profile in $AllProfiles)
{
$DisplayName = $profile.DisplayName
$AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
$Firstname = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::FirstName].Value
$Lastname = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::LastName].Value
$JobTitle=$profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::JobTitle].Value
$Title=$profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::Title].Value
$PictureUrl=$profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::PictureUrl].Value
$Office=$profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::Office].Value
$WorkPhone=$profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::WorkPhone].Value
$WorkEmail=$profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::WorkEmail].Value
$Departamento=$profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::Department].Value;
$MiCampoPersonalizado=$profile["MiCampoPersonalizado"].Value
#$User = $ProfileManager.GetUserProfile();
$data = @{
"DisplayName"=$DisplayName;
"AccountName"=$AccountName;
"FirstName"=$Firstname;
"Lastname"=$Lastname;
"JobTitle"=$JobTitle;
"Puesto"=$Title;
"PictureUrl"=$PictureUrl;
"Office"=$Office;
"WorkPhone"=$WorkPhone;
"WorkEmail"=$WorkEmail;
"Departamento"=$Departamento;
"MiCampoPersonalizado"=$MiCampoPersonalizado;
}
New-Object PSObject -Property $data
write-Host "Listando usuario.. $AccountName"
}
write-host "Finalizado."
$site.Dispose()
}
#$csvFilePath = "C:\PerfilesDeUsuario.csv"
#GetAllUserProfiles| Export-Csv -NoTypeInformation -Path $csvFilePath
GetAllUserProfiles | Out-GridView