powershell
powershell copied to clipboard
[BUG] Get-PnPSharePointAddIn does not works : The requested operation requires an element of type 'String', but the target element has type 'Null'.
Reporting an Issue or Missing Feature
Calling Get-PnPSharePointAddIn
fails with some obscure error message
Expected behavior
The command should return the list of installed addins
Actual behavior
The command fails:
Get-PnPSharePointAddIn | ~~~~~~~~~~~~~~~~~~~~~~ | The requested operation requires an element of type 'String', but the target element has type 'Null'.
Steps to reproduce behavior
Save in a file the following script and run it:
Import-Module PnP.PowerShell
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/somecollection" -Interactive
Set-PnPTraceLog -On -WriteToConsole -Level Debug -LogFile "$PSScriptRoot\log.txt"
Get-PnPSharePointAddIn
FYI, the log.txt
file is created but remains empty.
Trying to understand what's wrong, I can get some tip using these code:
Get-PnPSharePointAddIn
$err = $error[0]
$err.Exception | fl
Which returns:
ErrorRecord : The requested operation requires an element of type 'String', but the target element has type 'Null'.
TargetSite : Void ProcessRecord()
Message : The requested operation requires an element of type 'String', but the target element has type 'Null'.
Data : {}
InnerException :
HelpLink :
Source : PnP.PowerShell
HResult : -2146233079
StackTrace : at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 101
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPSharePointCmdlet.cs:line 120
at System.Management.Automation.CommandProcessor.ProcessRecord()
I don't think this is a permission or authentication issue, because the following code works (return installed addins):
$web = Get-PNPWeb
$apps = Get-PnPProperty -ClientObject $web -Property AppTiles
$apps | ? { $_.AppType -eq "Instance" } | Select Title,Id
What is the version of the Cmdlet module you are running?
PnP.Powershell : 2.2.0
$PSVersionTable
Name Value
---- -----
PSVersion 7.4.1
PSEdition Core
GitCommitId 7.4.1
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Which operating system/environment are you running PnP PowerShell on?
- [X] Windows
- [ ] Linux
- [ ] MacOS
- [ ] Azure Cloud Shell
- [ ] Azure Functions
- [ ] Other : please specify
Side note : the actual exception seems to be shallowed by this code:
https://github.com/pnp/powershell/blob/c42a224c5252159fde054df1da36268324a9b4e7/src/Commands/Base/PnPConnectedCmdlet.cs#L98-L102
Maybe you should keep in some way the actual exception and not only its error message?
you can get the actual exception if you pass -ErrorAction:Stop
to the cmdlet
@stevebeauge could you please try this to get the actual stacktrace ?
Get-PnPSharePointAddIn -ErrorAction:Stop
(Get-PnPException).Exception | Select-Object *
Also please try upgrading to v2.4.0 https://github.com/pnp/powershell/releases/tag/v2.4.0
Hello @jackpoz
Using PnP.PowerShell 2.2.0 (output not very useful):
╭─ ~ 2.246s ERROR 15:48:15 ─╮
╰─ Get-PnPSharePointAddIn -ErrorAction:Stop ─╯
Get-PnPSharePointAddIn: The requested operation requires an element of type 'String', but the target element has type 'Null'.
╭─ ~ 1.073s ERROR 15:48:22 ─╮
╰─ (Get-PnPException).Exception | Select-Object * ─╯
ErrorRecord : Property "InvocationInfo" cannot be found.
Message : Property "InvocationInfo" cannot be found.
ParamName : ExpandProperty
TargetSite :
Data : {}
InnerException :
HelpLink :
Source :
HResult : -2147024809
StackTrace :
Using 2.4.0, no issue:
╭─ ~ ✔ 15:46:17 ─╮
╰─ Get-PnPSharePointAddIn ─╯
AppInstanceId : 2c3356f5-5d0a-4fb4-904d-36f79a36268e
AppSource : SiteCollectionCorporateCatalog
AppWebFullUrl :
AppWebId : 00000000-0000-0000-0000-000000000000
AssetId :
CreationTime : 08/04/2024 13:44:56
InstalledBy : Steve BEAUGÉ
InstalledSiteId : XXXXXXXX
InstalledWebId : XXXXXXXX
InstalledWebFullUrl : https://XXXXXXXX.sharepoint.com/sites/XXXXXXXX
InstalledWebName : SBE 2022-12-22 _ 001
CurrentSiteId : XXXXXXXX
CurrentWebId : XXXXXXX
CurrentWebFullUrl : https://XXXXXXXX.sharepoint.com/sites/XXXXXXXX
CurrentWebName : SBE 2022-12-22 _ 001
LaunchUrl : https://sXXXXXXXXX.azurewebsites.net/?{StandardTokens}
LicensePurchaseTime : 01/01/0001 00:00:00
PurchaserIdentity :
Locale : fr-FR
ProductId : XXXXXXX
Status : Installed
TenantAppData :
TenantAppDataUpdateTime : 01/01/0001 00:00:00
AppIdentifier : XXXXXXX
ServerRelativeUrl : /sites/XXXXXX
Title : Solutions 365: XXXXXXX
AllowAppOnly : True
SiteCollectionScopedPermissions : {XXXXXXX,
990a16eb-1ae6-4175-b351-de7d1c9b5998}
TenantScopedPermissions : {}
if it works with 2.4.0 , then that's the solution to the issue 😃
Fair
We can close the issue.
Maybe there was something messed with an older version of the csom.
Thanks