Repository navigation
[BUG] New-PnPLibraryFileVersionBatchDeleteJob : Value cannot be null. (Parameter 'source') #4668
Description
Activity
Could you please add
-ErrorAction:Stopas additional parameter and then post the stacktrace runningGet-PnPException | select *?Added the
-ErrorAction:StopinNew-PnPLibraryFileVersionBatchDeleteJob -Identity $libraryName -MajorVersionLimit $majorLimit -MajorWithMinorVersionsLimit $minorLimit -ForceAdded
Write-Error (Get-PnPException | select *)output below:`ERROR: An error occurred: Value cannot be null. (Parameter 'source')
Exception :
Type : Microsoft.PowerShell.Commands.WriteErrorException
Message : An error occurred: Value cannot be null. (Parameter 'source')
HResult : -2146233087
CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,VersionHistory-Control
InvocationInfo :
MyCommand : VersionHistory-Control
HistoryId : 1
InvocationName : VersionHistory-Control
CommandOrigin : Internal
ScriptStackTrace : at , C:\home\site\wwwroot\VersionHistory-Control\run.ps1: line 137
PipelineIterationInfo :
0
0
52025-01-08T12:18:45Z [Error] ERROR: @{Message=An error occurred: Value cannot be null. (Parameter 'source'); Stacktrace=; ScriptLineNumber=0; InvocationInfo=System.Management.Automation.InvocationInfo; Exception=Microsoft.PowerShell.Commands.WriteErrorException: An error occurred: Value cannot be null. (Parameter 'source'); CorrelationId=; TimeStampUtc=1/1/0001 12:00:00 AM}
Exception :
Type : Microsoft.PowerShell.Commands.WriteErrorException
Message : @{Message=An error occurred: Value cannot be null. (Parameter 'source'); Stacktrace=; ScriptLineNumber=0; InvocationInfo=System.Management.Automation.InvocationInfo; Exception=Microsoft.PowerShell.Commands.WriteErrorException: An error occurred: Value cannot be null. (Parameter 'source'); CorrelationId=; TimeStampUtc=1/1/0001 12:00:00 AM}
HResult : -2146233087
CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,VersionHistory-Control
InvocationInfo :
MyCommand : VersionHistory-Control
HistoryId : 1
InvocationName : VersionHistory-Control
CommandOrigin : Internal
ScriptStackTrace : at , C:\home\site\wwwroot\VersionHistory-Control\run.ps1: line 138
PipelineIterationInfo :
0
0`Hello everyone! I'm not sure if I'll be helpful or not, but I see the same error when I'm trying to run this command on my Azure Function:
Add-PnPFile -Path "test1.csv" -Folder "Shared Documents/"I have a PnP PowerShell Cmdlets (2.99.142) version.
Could it be that you are using a ClientSecret to connect using Connect-PnPOnline and that ACS has been disabled on this tenant? I've seen this vague error getting thrown in that scenario. I've pushed a PR to PnP Framework to make this error at least a little less vague.
Use:Get-PnPTenant | Select DisableCustomAppAuthentication
To check if ACS is disabled on your tenant. It should report back False. If it reports back True, use Set-PnPTenant -DisableCustomAppAuthentication:$false to enable it or better yet, stop using ClientSecrets, start using certificates :)
Hello,
I am encountering the same issue in my tenant using Get-PnPSiteTemplate:
The command line I use is:
$ctxSp = Connect-PnPOnline -url "https://m365mystic.sharepoint.com/sites/CTypeTest-Manual" -ClientId $appId -Tenant $tenantId -Thumbprint $certThumbprint -ReturnConnection
Get-PnPSiteTemplate -Out template2.xml -Connection $ctxSp -IncludeAllPages
Get-PnPSiteTemplate: Value cannot be null. (Parameter 'source')As you can see the connection is created without error so the appID/certificate info used to connect, but when I run Get-PnPSiteTemplate it throws the error. There is no '-Source' parameter for this cmdlet per the documentation.
The interesting thing is, in another tenant where I tried this, it works fine. Both tenants have "DisableCustomAppAuthentication:False".
Do you know if there is some more recent change rolling out to tenants currently that might cause this failure in all tenants in the future (not including the switch away from the App Model that will require "DisableCustomAppAuthentication :True" come April 2026?
Thanks
Could it be that you are using a ClientSecret to connect using Connect-PnPOnline and that ACS has been disabled on this tenant? I've seen this vague error getting thrown in that scenario. I've pushed a PR to PnP Framework to make this error at least a little less vague. Use:
Get-PnPTenant | Select DisableCustomAppAuthentication
To check if ACS is disabled on your tenant. It should report back False. If it reports back True, use Set-PnPTenant -DisableCustomAppAuthentication:$false to enable it or better yet, stop using ClientSecrets, start using certificates :)Tried getting ACS using certificates. and already enabled the CustomAppAuthentication. Here's the Exception from when running locally
Get-PnPException | select *
Message : Value cannot be null. (Parameter 'source')
Stacktrace : at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable1 source, Boolean& found) at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source)
at PnP.Framework.Http.HttpClientSPWebRequestExecutor.get_ResponseContentType()
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServerAsync(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryAsync()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQueryAsync()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQueryAsync()
at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, String userAgent)
at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(ClientRuntimeContext clientContext, Int32 retryCount, String userAgent)
at PnP.PowerShell.Commands.PnPWebCmdlet.GetWeb() in D:\a\powershell\powershell\src\Commands\Base\PnPWebCmdlet.cs:line 41
at PnP.PowerShell.Commands.PnPWebCmdlet.get_CurrentWeb() in D:\a\powershell\powershell\src\Commands\Base\PnPWebCmdlet.cs:line 27
at PnP.PowerShell.Commands.Lists.NewLibraryFileVersionBatchDeleteJob.ExecuteCmdlet() in
D:\a\powershell\powershell\src\Commands\Lists\NewLibraryFileVersionBatchDeleteJob.cs:line 69
at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPConnectedCmdlet.cs:line 55
ScriptLineNumber : 1
InvocationInfo : System.Management.Automation.InvocationInfo
Exception : System.ArgumentNullException: Value cannot be null. (Parameter 'source')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable1 source, Boolean& found) at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source)
at PnP.Framework.Http.HttpClientSPWebRequestExecutor.get_ResponseContentType()
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServerAsync(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryAsync()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQueryAsync()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQueryAsync()
at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, String userAgent)
at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(ClientRuntimeContext clientContext, Int32 retryCount, String userAgent)
at PnP.PowerShell.Commands.PnPWebCmdlet.GetWeb() in D:\a\powershell\powershell\src\Commands\Base\PnPWebCmdlet.cs:line 41
at PnP.PowerShell.Commands.PnPWebCmdlet.get_CurrentWeb() in D:\a\powershell\powershell\src\Commands\Base\PnPWebCmdlet.cs:line 27
at PnP.PowerShell.Commands.Lists.NewLibraryFileVersionBatchDeleteJob.ExecuteCmdlet() in
D:\a\powershell\powershell\src\Commands\Lists\NewLibraryFileVersionBatchDeleteJob.cs:line 69
at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPConnectedCmdlet.cs:line 55
CorrelationId :
TimeStampUtc : 10/04/2025 13:26:48DisableCustomAppAuthentication is set to false (we are using another app that requires this for now). I connect using:
$ctxSp = Connect-PnPOnline -url "https://m365mystic.sharepoint.com/sites/CTypeTest-Manual" -ClientId $appId -Tenant $tenantId -Thumbprint $certThumbprint -ReturnConnection
which leverages an app registration in the tenant (hence $appId ) and a certificate to connect.
I'm also having this problem with Get-PnPSiteTemplate on delegated permission/login
Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/sitename" -ClientID "<app_registration_id>" -Interactive Get-PnPSiteTemplate -Out "template.xml"For what it's worth in the powershell output I can see it going through:
"extracting Template from https://contoso.sharepoint.com/site. [Regional Settings ]
"extracting Template from https://contoso.sharepoint.com/site. [Supported UI Languages ]
"extracting Template from https://contoso.sharepoint.com/site. [Audit Settings ]
"extracting Template from https://contoso.sharepoint.com/site. [Site Security ]and it seems to fail after that.

Reporting an Issue or Missing Feature
Powershell usage for the
New-PnPLibraryFileVersionBatchDeleteJobthrows an error: Value cannot be null. (Parameter 'source') when running. Current testing is in Azure FunctionExpected behavior
Command should run the and queue the File Version Batch Delete Job
Actual behavior
Error is being produce on the line for
New-PnPLibraryFileVersionBatchDeleteJob -Identity $libraryName -MajorVersionLimit $majorLimit -MajorWithMinorVersionsLimit $minorLimit -ForceValue cannot be null. (Parameter 'source')Steps to reproduce behavior
Connect-PnPOnline -Url $siteUrl -AccessToken $AccessToken
New-PnPLibraryFileVersionBatchDeleteJob -Identity $libraryName -MajorVersionLimit $majorLimit -MajorWithMinorVersionsLimit $minorLimit -Force
What is the version of the Cmdlet module you are running?
currently using the 2.99.97-nightly
Which operating system/environment are you running PnP PowerShell on?