Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am cereating a Poweshell script to add data in Office 365 list on intervals.

I am able to create script sucessfully and executing it in SharePoint Online Management Shell.
This is my code.
$siteUrl = "site URL";
$listName = "List"
$userName  = "user name";
$password = "password";
$SecurePassword = $password | ConvertTo-SecureString -AsPlainText -Force
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $SecurePassword)
$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$context.Credentials = $credentials
[Microsoft.SharePoint.Client.Web]$web = $context.Web
[Microsoft.SharePoint.Client.List]$list = $web.Lists.GetByTitle($listName)
[Microsoft.SharePoint.Client.ListItemCreationInformation]$itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation;
[Microsoft.SharePoint.Client.ListItem]$item = $list.AddItem($itemCreateInfo);
$item["Title"] = "title";
$item.Update();
$context.ExecuteQuery();


I am creating one task in Task Schedular that executes script in every 5 minutes.
When I register any other local script, it works fine.

But when I register my PowerShell script that add data in Office 365 list, it neither works nor throws any error.

Can anyone suggest how can I schedule my Poweshell script for Office 365.

Be an open to give any suggestion.

Thank you

What I have tried:

Created Scheduler with this script. It works fine manually but didn't worked with scheduler
Posted
Updated 8-Mar-16 3:07am

1 solution

You must add the SharePoint Snap-in to the Windows PowerShell using the command
Add-PSSnapin Microsoft.SharePoint.PowerShell


See also Running a SharePoint PowerShell script from Task Scheduler | Get-SPScripts : PowerShell Scripts for SharePoint[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900