# Need help with powershell and sharepoint 2007 on 2008 windows server

**URL:** <https://forums.powershell.org/t/need-help-with-powershell-and-sharepoint-2007-on-2008-windows-server/14246>\
**Category:** PowerShell Help\
**Created:** [April 24, 2020, 10:12am UTC](https://forums.powershell.org/t/need-help-with-powershell-and-sharepoint-2007-on-2008-windows-server/14246 "2020-04-24T10:12:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill\_proctor](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bill\_proctor](https://forums.powershell.org/u/bill_proctor)\
**Post date:** [April 24, 2020, 10:12am UTC](https://forums.powershell.org/t/need-help-with-powershell-and-sharepoint-2007-on-2008-windows-server/14246/1 "2020-04-24T10:12:59Z")

</div>

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

I PS H:\\> $webUrl = New-Object Microsoft.SharePoint.spsite (“[http://mysite”)](http://sharepointit.tgslc.org/TS/admin/Requisition%20Request%20Form%20Library/Forms/All%20Reqs1.aspx%E2%80%9D) "http://sharepointit.tgslc.org/ts/admin/requisition%20request%20form%20library/forms/all%20reqs1.aspx”)")New-Object : Cannot find type [Microsoft.SharePoint.spsite]: verify that the assembly containing this type is loaded.
&nbsp;

Code:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$webUrl = New-Object Microsoft.SharePoint.spsite (“http://mysite ”)

$library = "Technology Services (TS)" $tempLocation = "D:\transfer\Attachments" $s = new-object Microsoft.SharePoint.SPSite($webUrl) $web = $site.OpenWeb() $l = $w.Lists[$library]

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()  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [April 24, 2020, 1:30pm UTC](https://forums.powershell.org/t/need-help-with-powershell-and-sharepoint-2007-on-2008-windows-server/14246/2 "2020-04-24T13:30:33Z")

</div>

Sorry if this is a dumb question, but you are running the script on the SP server itself and or have it setup for SharePoint remoting?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/need-help-with-powershell-and-sharepoint-2007-on-2008-windows-server/14246/3 "2024-05-16T20:29:51Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


