Need help with powershell and sharepoint 2007 on 2008 windows server

Welcome Forums General PowerShell Q&A Need help with powershell and sharepoint 2007 on 2008 windows server

  • This topic has 1 reply, 2 voices, and was last updated 1 month ago by
    Participant
    .
Viewing 1 reply thread
  • Author
    Posts
    • #222204
      Participant
      Topics: 2
      Replies: 0
      Points: 23
      Rank: Member

      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”)New-Object : Cannot find type [Microsoft.SharePoint.spsite]: verify that the assembly containing this type is loaded.

       

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

    • #222252
      Participant
      Topics: 6
      Replies: 93
      Points: 427
      Helping Hand
      Rank: Contributor

      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?

Viewing 1 reply thread
  • You must be logged in to reply to this topic.