Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Introduction
Most SharePoint IT Pros are aware of the issues in SharePoint Online Management PowerShell Module and we are not going to cover all in this TechNet Wiki article. Instead we will highlight an issue with one of the cmdlet Get-SPOAppInfo. Load the SharePoint Online Management PowerShell module and read the parameter help documentation.
Okay, It's clear both the parameters are not mandatory. So we tried retrieving the App information using Get-SPOAppInfo and ended up with below error. Indeed, it works if we pass values to any of the parameters by either name or GUID of the product and that works! But it's not going to retrieve the information we need. If we know the name or product ID we will not use this cmdlet!
See the below image
Solution
You need to load the CSOM assemblies before executing the script. In our case the CSOM SDK package is installed in "C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\ and assembly (DLL) files are located in the net45 folder.
We need output like shown below!
To install CSOM Package refer to this link and please choose the version accordingly! In our example we opted for the latest version.
Code
- Import only the required assemblies
- Define parameters as required
- URL should be tenant admin URL E.G.
https://contoso-admin.sharepoint.com
- We defined credential parameter as mandatory for a demo (Environment Set Up)
- Instantiate the classes shown the code
- Get the app information in one go
- You can choose the properties required by using Select-Object
- E.G
$AppInfo | Select Name , Source, ProductID
- E.G
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.SharePoint.Client.dll'
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll'
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.Online.SharePoint.Client.Tenant.dll'
function Get-xSPOAppInfo
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$SPOUrl,
[Parameter(Mandatory=$true)]
[System.Management.Automation.CredentialAttribute()]
[pscredential]
$SPOCredential
)
Process
{
$ClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($SPOUrl)
$ClientContext.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($SPOCredential.UserName,$SPOCredential.Password)
$oTenant = [Microsoft.Online.SharePoint.TenantAdministration.Tenant]::new($ClientContext)
if($oTenant.ServerObjectIsNull.Value -ne $true)
{
try
{
$ClientContext.Load($oTenant)
$AppInfo = $oTenant.GetAppInfoByName([String]::Empty)
$ClientContext.Load($AppInfo)
$ClientContext.ExecuteQuery()
$ClientContext.Dispose()
$AppInfo
}
catch
{
$_.Exception.Message
}
}
}
}
Get-xSPOAppInfo -SPOUrl "https://contoso-admin.sharepoint.com" -SPOCredential "SPAdmin@contoso.onmicrosoft.com"