1

I have two identincal SharePoint 2007 lists.

Can I use powershell to do the following:

  1. Copy the first list into the second with all it's item version history.
  2. Remove all version history from the first list
  3. Clean out some 15 columns for every item on the first list

Also, what's the best way to make that powershell script executable to a user via a button on a webpage within SharePoint 2007?

Any help on what this script might look like is greatly appreciated!

Hell.Bent
  • 1,667
  • 9
  • 38
  • 73

1 Answers1

0

Since you can use any DLL from PowerShell, yes, you can use SharePoint API from PowerShell.

Basically you can

  1. stsadm extension gl-copylist command to clone list (you can call that command from PowerShell anyway)
  2. There is already a PowerShell script to disable versioning, but it involves all lists - you can probably get out the chunk you need.
  3. Call SPList.Fields["fieldToDelete"].Delete(); to delete field on the list.

About #2 - Not sure about this one, but you can try to set SPList.EnableVersioning to false, .Update(), and then to true and see if it removes versions automatically.

To access SharePoint API from powershell, execute (read more here):

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

Note, you can do it only from computer SharePoint is installed on. Other way around, you would have to talk to PowerShell throught web services.

Janis Veinbergs
  • 6,907
  • 5
  • 48
  • 78