I am using following powershell (that I got from here http://spsatheesh.wordpress.com/2011/06/03/download-all-the-profile-pictures-through-powershell-using-web-service/)so I can download all the profile pictures. The script runs and displays index number and the profile id (with domain) on the screen. however, profile pictures are not saved.
= = = script = = =
[system.reflection.assembly]::LoadWithPartialName("System.IO")
[system.reflection.assembly]::LoadWithPartialName("System.Web")
$SUrl = 'https://yourcompany.com/_vti_bin/userprofileservice.asmx?wsdl'
$filename = 'report.csv'
function Download()
{
trap [Exception]
{
Write-Output "-------------------------------Error"
Write-Output $_.Exception.Message
Write-Output "-------------------------------Error"
continue
}
$datel = Get-Date
Write-Output "INFO: `t $datel `t Job Started"
Write-Host "Set Path to Store Pictures"
$FilePath = Read-Host
if($FilePath.EndsWith("\") -eq $false)
{
$FilePath = $FilePath + "\"
}
Write-Host "Enter the User Profile Web Service Url"
$SUrl = Read-Host
Write-Host "Enter the User name & Password using which it needs to connect the service"
#Create Credential Object
$Credential = Get-Credential
#Get Service
#$Service = New-WebServiceProxy -Uri $SUrl -NameSpace UserProfileService -UseDefaultCredential
$Service = New-WebServiceProxy -Uri $SUrl -NameSpace UserProfileService -Credential $Credential
#Create WebRequest
$WebRequest = new-object System.Net.WebClient
#$WebRequest.Credentials = [System.Net.CredentialCache]::DefaultCredentials
#$WebRequest.Credentials = new-object System.Net.NetworkCredential("palnisam","password","domain")
$WebRequest.Credentials = $Credential.GetNetworkCredential()
#[IO.Directory]::SetCurrentDirectory((Convert-Path (Get-Location -PSProvider FileSystem)))
#$Reader = new-object System.IO.StreamReader($filename)
$ProfileCount = $Service.GetUserProfileCount()
$ProfileLoop = 0;
$NextIndex = 358;
for($ProfileLoop = 0;$ProfileLoop -le $ProfileCount;$ProfileLoop++)
{
trap [Exception]
{
}
$UPD = $Service.GetUserProfileByIndex($NextIndex)
$AccountName = $UPD.UserProfile[1].Values[0].Value
$PictureURL = $UPD.UserProfile[20].Values[0].Value
if($PictureURL -ne $null)
{
$FileName = $FilePath +$AccountName.SubString($AccountName.LastIndexOf("\")+1) + $PictureUrl.SubString($PictureUrl.LastIndexOf("."))
$WebRequest.DownloadFile($PictureUrl,$FileName)
}
$NextIndex = $UPD.NextValue
Write-Host "$ProfileLoop ----- $AccountName"
}
}