- Copy “GetUserProperties.bat” and “GetUserProperties.ps1” files to some location on any WFE servers of production.
- Double click the batch file which generates a csv file (c:\ GetUserProperties.csv) with the list of user profile
- Save this file as xlsx, so that we can view it properly.
Code for GetUserProperties.ps1
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# Enter your SharePoint site URL here...
$site = new-object Microsoft.SharePoint.SPSite("https://mysite.progress.com");
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);
$ProfileManager = new-object
Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
$AllProfiles = $ProfileManager.GetEnumerator()
write-host "UserName ,AccountName , Manager ,PictureURL"
foreach($profile in $AllProfiles)
{
$DisplayName = $profile.DisplayName
$AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
$Picturevalue = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::PictureURL].Value
$Manager = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::Manager].Value
if($Picturevalue -ne "" )
{
write-host $DisplayName","$AccountName","$Manager","$Picturevalue
}
else
{
write-host $DisplayName","$AccountName","$Manager","$Picturevalue
}
}
$site.Dispose()
Code for GetUserProperties.bat:
cd /d %~dp0
powershell -noexit -file ".\GetUserProperties.ps1" "%CD%" >> "c:\GetUserProperties.csv"
pause
No comments:
Post a Comment