I know very little powershell but I’ve been nominated to extract all attachments from our 2007 sharepoint server before it gets shut down. I’m trying to run the script below but keep getting errors on the new-object Microsoft.sharepoint.spsite
Code:
foreach ($listItem in $l.Items)
{
Write-Host " Content: " $listItem.ID
$destinationfolder = $tempLocation + "" + $listItem.ID
if($listItem.Attachments.Count -gt 0)
{
if (!(Test-Path -path $destinationfolder))
{
$dest = New-Item $destinationfolder -type directory
}
foreach ($attachment in $listItem.Attachments)
{
$file = $w.GetFile($listItem.Attachments.UrlPrefix + $attachment)
$bytes = $file.OpenBinary()
$path = $destinationfolder + "" + $attachment
Write “Saving $path”
$fs = new-object System.IO.FileStream($path, “OpenOrCreate”)
$fs.Write($bytes, 0 , $bytes.Length)
$fs.Close()
}
}
}