function Upload-SPDocument([string]$url, [string]$Folder, [string]$Document, [string]$Year, [string]$Location) { $spAssignment = Start-SPAssignment $SPWeb = Get-SPWeb $url -AssignmentCollection $spAssignment $DocumentName = Split-Path $Document -Leaf $spFolder = $SPWeb.GetFolder($Folder) $spFileCollection = $spFolder.Files $spFile = $spFileCollection.Add("$Folder/$DocumentName",$((gci $Document).OpenRead())) $spFile.Item["Title"] = $DocumentName $spFile.Item["Year"] = $Year $spFile.Item["Location"] = $Location $spFile.Item.Update() Stop-SPAssignment $spAssignment } $Sydney = Get-ChildItem C:\Demo\Documents\Sydney -Recurse | Where { $_.Attributes -notmatch "Directory" } | Select FullName, @{Name="Year";Expression={($_.CreationTime).Year}}, @{Name="Location";Expression={"Sydney"}} $Wellington = Get-ChildItem C:\Demo\Documents\Wellington -Recurse | Where { $_.Attributes -notmatch "Directory" } | Select FullName, @{Name="Year";Expression={($_.CreationTime).Year}}, @{Name="Location";Expression={"Wellington"}} $Files = $Sydney + $Wellington $Files | ForEach { Upload-SPDocument -url http://SPServer01 -Folder "Shared Documents" -Document $($_.FullName) -Year $($_.Year) -Location $($_.Location) }