Home

SharePoint on Prem - Update List

%3CLINGO-SUB%20id%3D%22lingo-sub-1277935%22%20slang%3D%22en-US%22%3ESharePoint%20on%20Prem%20-%20Update%20List%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1277935%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3CBR%20%2F%3EI%20am%20running%20a%20Powershell%20to%20update%20a%20list.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EWhile%20running%20this%20powershell%20with%20my%20user%20account%20the%20columns%20are%20updated.%3C%2FP%3E%3CP%3EWhile%20running%20this%20powershell%20through%20taks-scheduler%20(other%20user)%20the%20data%20within%20the%20columns%20are%20dropped%20but%3C%2FP%3E%3CP%3Enot%20updated.%20The%20user%20from%20task-scheduler%20is%20owner%20of%20the%20specific%20list.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20could%20be%20the%20reason.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%3C%2FP%3E%3CP%3EJ.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1277935%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1280401%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20on%20Prem%20-%20Update%20List%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1280401%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3ETry%20to%20use%20try-catch%20block%20within%20the%20PowerShell%20to%20capture%20for%20any%20issues.%20If%20there%20is%20no%20issue%2C%20then%20the%20fields%20are%20skipped%20because%20of%20the%20permission%2C%20make%20sure%20the%20scheduler%20run%20on-behalf%20of%20the%20user%20who%20has%20permission%20to%20update%20the%20fields.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1283665%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20on%20Prem%20-%20Update%20List%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1283665%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F144422%22%20target%3D%22_blank%22%3E%40Sudharsan%20K%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%3CBR%20%2F%3EThank%20you%20for%20your%20input.%3C%2FP%3E%3CP%3EI%20did%20already%20run%20try-catch%26nbsp%3Band%20no%20errors%3C%2FP%3E%3CP%3EThe%20task-Scheduler%20runs%20with%20an%20technical%20user%20with%20highest%20privileges.%3C%2FP%3E%3CP%3EThe%20funny%20Thing%20user%20drops%20the%20data%20within%20the%20column%20but%20does%20not%20inserts%20the%20data.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20the%20sample%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24items%20%3D%20%24list.Items%0A%0A%20%20%20%20foreach(%24item%20in%20%24items)%0A%20%20%20%20%7B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%24owner%20%3D%20%24item%5B'Besitzer'%5D%0A%20%20%20%20%20%20%20%20%24ownertest%20%3D%20%24owner%20-replace%20%22.*%23%22%0A%20%20%20%20%20%20%20%20%24costcentercsv%20%3D%20%24CSVData%20%7C%20Where-Object%20%7B%24_.UsEMail%20-eq%20%24ownertest%7D%20%7C%20%25%20UsAccountNum%0A%20%20%20%20%20%20%20%20%24item%5B%24costcenter%5D%20%3D%20%24costcentercsv%0A%20%20%20%20%20%20%20%20%24item.Update()%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%0A%20%20%20Catch%0A%20%20%20%7B%0A%20%20%20%20%20%24logger.LogError(%22Exception%20raised%22)%0A%20%20%20%20%20%24logger.LogException(%24_.Exception)%0A%20%20%20%20%20%24script%3AsitesErrors%20%3D%20%24script%3AsitesErrors%20%2B%201%0A%20%20%20%20%20%24script%3AscriptError%20%3D%20%24true%0A%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hello
I am running a Powershell to update a list.


While running this powershell with my user account the columns are updated.

While running this powershell through taks-scheduler (other user) the data within the columns are dropped but

not updated. The user from task-scheduler is owner of the specific list.

 

What could be the reason.

 

Thank you

J.

2 Replies
Highlighted
Hi,
Try to use try-catch block within the PowerShell to capture for any issues. If there is no issue, then the fields are skipped because of the permission, make sure the scheduler run on-behalf of the user who has permission to update the fields.
Highlighted

@Sudharsan K 

Hello
Thank you for your input.

I did already run try-catch and no errors

The task-Scheduler runs with an technical user with highest privileges.

The funny Thing user drops the data within the column but does not inserts the data.

 

Here the sample:

$items = $list.Items

    foreach($item in $items)
    {        
        $owner = $item['Besitzer']
        $ownertest = $owner -replace ".*#"
        $costcentercsv = $CSVData | Where-Object {$_.UsEMail -eq $ownertest} | % UsAccountNum
        $item[$costcenter] = $costcentercsv
        $item.Update();
        
     }
    }
   
   Catch
   {
     $logger.LogError("Exception raised")
     $logger.LogException($_.Exception)
     $script:sitesErrors = $script:sitesErrors + 1
     $script:scriptError = $true
   }

 

Regards