Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a PowerShell script that pulls data from a database. I need to push this data to a SharePoint list on a different server.

Would you have tutorial or examples that show how to do this (authentication and update)?

Update: I need this to work on both SharePoint 2007 and 2010. I do not have admin access on the SharePoint server.

share|improve this question
    
I really appreciate the help I have received. I am in the process of testing the solutions and will report back soon. –  Christophe Sep 9 '11 at 17:18
    
I upvoted the replies I found useful, but didn't mark any as answer as I wasn't able to make it work. –  Christophe Oct 26 '11 at 5:41
add comment

4 Answers

Not sure I would use PowerShell for this.

Why not use Business Connectivity Service (SP2010) or Business Data Catalog (SP2007) for this?

If you need to move data redundantly into a list in SharePoint with certain intervals another option would be SQL Integration Services.

share|improve this answer
    
I feel this is migration issue (one time job). Maybe I am wrong and maybe this question needs some extra info. Still, BCS/BDC is solution if there is need to 'connect' two lists on different servers so +1 –  Vedran Rasol Sep 6 '11 at 20:20
    
@Anders: I added some info to explain the context. Thanks for the advice, it just won't work in my specific case. –  Christophe Sep 7 '11 at 0:20
add comment

Given the information I would still chose to do a console app that leverages SharePoint's web services versus using PowerShell with remoting. If you need it to work with both, then I would stick with the soap based services. http://msdn.microsoft.com/en-us/library/ms479390(v=office.12).aspx

share|improve this answer
    
Powershell is used to pull data from a non-SharePoint database, I have no choice here. My job is to extend the existing script to have it interact with SharePoint. Is there a way to make Powershell work with SP Web Services? And in this case how do I authenticate? –  Christophe Sep 7 '11 at 1:01
1  
I didn't understand that your only option for consuming the other data was via the powershell script. I mistakenly thought that it was just the way you had intended on getting it. Authentication to the web service should be based on the credentials of the user making the request, in this case the one executing the powershell. I haven't called a web service from PowerShell yet, but here is a blog that covers it. fatbeards.blogspot.com/2010/03/… –  Mike Oryszak Sep 7 '11 at 1:14
    
In my case the credentials are for the first server, not SharePoint. I was hoping to pass a username and password from within the script. –  Christophe Sep 7 '11 at 1:25
    
Did a quick bing search and came back with this... brangle.com/wordpress/2009/08/pass-credentials-via-powershell –  Mike Oryszak Sep 7 '11 at 12:17
add comment

This is my second answer since question was updated.

I was following link provided by @MikeOryszak and I did some testing. This is the PowerShell script that uses SP web service with custom credentials to insert data:

$items #ListItem collection

$siteUrl = "http://mySite"
$fieldsToCopy = @("Title", "SomeOtherField") #fields to copy

#Build batch
$batch = "<Batch>"
for ($index = 0; $index -lt $items.Count; $index++) {
    $methodId = $index + 1
    $batch +=  "<Method ID='$methodId' Cmd='New'><Field Name='ID'>New</Field>"
    foreach ($field in $fieldsToCopy) {
            $fldValue = $items[$index][$field]
            $batch += "<Field Name='$field'>$fldValue</Field>"
    }
    $batch += "</Method>"
}
$batch += "</Batch>"

#Make webservice call
$wsProxy = New-WebServiceProxy -Uri $siteUrl/_vti_bin/lists.asmx -Credential [DOMAIN\USER]
#You will be prompted for password
$xmlB = [xml]$batch 
($wsProxy.UpdateListItems($targetListId, $xmlB )).ResultStatus

Note: I have tested this on single server only with 'primitive' field types and it is working. There are many ways this script can be upgraded but I have done this just as 'proof of concept'

share|improve this answer
add comment

You can use the SharePoint Webservices from your Client. It´s only necessary that PowerShell 2.0 is running on your Client. You don´t need any Admin priviliges on the SharePoint.

Use the following code:

$Credential = New-Object System.Management.Automation.PSCredential('test\user',(Read-Host "Enter Password" -AsSecureString)) 
$SPList = New-WebServiceProxy -uri http://yoursharepoint.de/_vti_bin/lists.asmx –Credential $Credential

http://technet.microsoft.com/de-de/library/dd315258.aspx

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.