Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,176 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello Everyone
I am trying to run a Scheduled task, that should run a powershell script every evening. Even though I can run the script with the SYSTEM-USER without any issues, it does not work when I try to run over task scheduler.
Here is the script I am using:
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
import-module Pnp.Powershell
$url = "myurl"
Connect-PnPOnline -Url $url -ClientId MYID -Tenant 'URL' -Thumbprint "THUMBPRINTID"
$files = Get-Childitem "CHILDITEMPATH" -Filter *.csv -Force -Recurse
foreach($File in $Files)
{
Add-PnPFile -Path "$($File.Directory)\$($File.Name)" -Folder "/sites/path/to/folder"
}
Do you have an Idea what this could be?
Thank you for your help.
Kind regards,
Gabriel
Generate a transcript and add diagnostic statements. Check the log file for errors.
start-transcript -path C:\Temp\MyScript.log
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
import-module Pnp.Powershell
$url = "myurl"
Connect-PnPOnline -Url $url -ClientId MYID -Tenant 'URL' -Thumbprint "THUMBPRINTID"
$files = Get-Childitem "CHILDITEMPATH" -Filter *.csv -Force -Recurse
"We found {0} files." -f $files.count
foreach($File in $Files)
{
"File: {0}" -f $file.name
Add-PnPFile -Path "$($File.Directory)\$($File.Name)" -Folder "/sites/path/to/folder"
}
stop-transcript