Hi Guys,
So I have this script that I have been trying to cobble together with another script, I found them both online.
One uploads photos from a network drive to the mysites/user profile list, the other is to look at the items in a list, in this case, the photos that are already in the mysites/user profile library, and then I am trying to compair the photos name to see if I don't need to upload the photo. the issue I am having is that no matter what I try, I always end up uploading all the photos. If anyone could help that would be great!!
Thanks a lot!
here is the script:
cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
#Setup default variables
$webUrl = "http://sps-dev-01/my"
$picLibraryName = "User Photos"
$picFolderName = "Profile Pictures"
$localFolderPath = "\\MyStoredPhotos" #-- change to wherever your photos are stored
$web = Get-SPweb $webUrl
$picFolder = $web.Folders["User Photos"].SubFolders["Profile Pictures"]
if(!$picFolder)
{
Write-Host "Picture Library Folder not found"
return
}
$sourceWebURL = "http://sps-dev-01/my"
$sourceListName = "User Photos"
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$spSourceItems = $spSourceList.GetItems()
$spSourceItems | ForEach-Object {
$a = Write-Host $_['Name']
$b = $_.Name
if($a -eq $b){
Write-Host $_.Name "already exists"
}else
{
#Attach to local folder and enumerate through all files
$files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles() | ForEach-Object {
#Create file stream object from file
$fileStream = ([System.IO.FileInfo] (Get-Item $_.FullName)).OpenRead()
$contents = new-object byte[] $fileStream.Length
$fileStream.Read($contents, 0, [int]$fileStream.Length);
$fileStream.Close();
write-host "Copying" $_.Name "to" $picFolder.Title "in" $web.Title "..."
#Add file
$spFile = $picFolder.Files.Add($picFolder.Url + "/" + $_.Name, $contents, $true)
$spItem = $spFile.Item
#Check in file to picture library
#MinorCheckIn=0, MajorCheckIn=1, OverwriteCheckIn=2
#$spFile.CheckIn("File copied from " + $filePath, 1)
#if ($spFile.CheckOutStatus -eq "None") { write-host $spfile.Name"checked in" }
#Approve file
}
}
}
Best regards, Mike








