none
add items to a list with remote powershell

    Question

  • Hi,

    I'm trying to add an item to a calendar list remotely from powershell. I can do it fine directly from the server by just removing the first 5 lines in the code. The userinput in get-credential has the correct permissions however when I analyze the code it seems that the $list variable is null and therefore it doesnt work. However any ideas on how I can fix this?

    Thanks

    $c = Get-Credential \
    $session = New-PSSession <Sharepointserver>-Authentication CredSSP -Credential $c
    
    #Add SharePoint PowerShell Snapin which adds SharePoint specific cmdlets
    Invoke-Command -Session $session -ScriptBlock{Add-PsSnapin Microsoft.SharePoint.PowerShell} 
    
    
    # Variables that we are going to use for list editing
    $webURL = "http://sharepointserver/sites/somesite"
    $listName = "Somecalendar" 
    
    #Get the SPWeb object and save it to a variable
    
    $web = Invoke-Command -Session $session -ScriptBlock{Get-SPWeb $webURL}  
    
    #Get the SPList object to retrieve the "Somecalendar"
    $list = $web.Lists[$listName]
    
    #Create a new item
    $newItem = $list.Items.Add() 
    
    #Add properties to this list item
    $newItem["Title"] = "My first appointment" 
    $newItem["Description"] = "This is a multiple lines of text field." 
    
    #Update the object so it gets saved to the list
    $newItem.Update()


    • Edited by Jan Knudsen Friday, January 04, 2013 2:02 PM
    Friday, January 04, 2013 2:00 PM

All replies

  • Anyone?

    I've just tried to make it more "simple" with a few screenshots. The first one works locally from the server:

    The second is from my remote computer and here I dont get any values back when I ask for $web.title or $list.title. The username/password I use is the same both places.

    Thanks

    Monday, January 07, 2013 12:44 PM
  • Anyone?

    I've just tried to make it more "simple" with a few screenshots. The first one works locally from the server:

    The second is from my remote computer and here I dont get any values back when I ask for $web.title or $list.title. The username/password I use is the same both places.

    Thanks

    Monday, January 07, 2013 12:44 PM