Forum Discussion
PowerShell doens't run correctly from scheduled task Job
- Apr 03, 2024I guess adding import-module PnP.Powershell should fix that. (Add it as the second line in the script after the Start-Transcript)
Hi Harm_Veenstra ,
The "-Scope Current user" worked and now it is throwing error for Connect-PnPOnline which says not recognized.
Below is the error:
Transcript started, output file is C:\temp\log.txt
Connect-PnPOnline : The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:14 char:1
+ Connect-PnPOnline -Url $siteUrl -Credentials $cred
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Connect-PnPOnline : The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:14 char:1
+ Connect-PnPOnline -Url $siteUrl -Credentials $cred
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Get-PnPListItem : The term 'Get-PnPListItem' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:18 char:17
+ $calendarData = Get-PnPListItem -List $listName
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-PnPListItem:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Get-PnPListItem : The term 'Get-PnPListItem' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:18 char:17
+ $calendarData = Get-PnPListItem -List $listName
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-PnPListItem:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Disconnect-PnPOnline : The term 'Disconnect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:40 char:1
+ Disconnect-PnPOnline
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Disconnect-PnPOnline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Disconnect-PnPOnline : The term 'Disconnect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:40 char:1
+ Disconnect-PnPOnline
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Disconnect-PnPOnline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Connect-PnPOnline : The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:44 char:1
+ Connect-PnPOnline -Url $siteUrlDestination -UseWebLogin
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Connect-PnPOnline : The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:44 char:1
+ Connect-PnPOnline -Url $siteUrlDestination -UseWebLogin
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Get-PnPListItem : The term 'Get-PnPListItem' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:48 char:10
+ $items = Get-PnPListItem -List $listNameDestination
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-PnPListItem:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Get-PnPListItem : The term 'Get-PnPListItem' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:48 char:10
+ $items = Get-PnPListItem -List $listNameDestination
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-PnPListItem:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Disconnect-PnPOnline : The term 'Disconnect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:70 char:1
+ Disconnect-PnPOnline
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Disconnect-PnPOnline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Disconnect-PnPOnline : The term 'Disconnect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Calendar\Leave_extraction_script.ps1:70 char:1
+ Disconnect-PnPOnline
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Disconnect-PnPOnline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
This worked well when running manually the script.