SharePoint Connect-PnPOnline : AADSTS700016

I have a ps1 file running in powershell started by a SSIS job which connects to sharepoint and downloads excel files.

Here the first part of the script that cause error:

$SiteURL = "https://mycompany.sharepoint.com/proj"

$UserName="myUsername"
$Password = "myPassword"
 
$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
 
#connect to sharepoint online site using powershell
Connect-PnPOnline -Url $SiteURL -Credentials $Cred

Since last week the job continuously goes into error, this is the message:

Connect-PnPOnline : AADSTS700016: Application with identifier '31359c7f-bd7e-475c-86db-fdb8c937548e' was not found in the directory 'mydirectory'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
Trace ID: 59f79c96-52f1-418e-b33a-fbe8e75d3200
Correlation ID: fd203fca-72c1-4ce1-bc4c-92d639b47ccc
Timestamp: 2024-09-16 07:59:07Z
At C:mypathSPDownload.ps1:12 char:1
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo          : NotSpecified: (:) [Connect-PnPOnline], MsalServiceException
FullyQualifiedErrorId : Microsoft.Identity.Client.MsalServiceException,PnP.PowerShell.Commands.Base.ConnectOnline

I tried connecting manually by opening sharepoint and running the command but I get the same error.

I just ran into this issue. I am getting it straightened out, but here is more information on what happened and how to fix it:

“As part of a focus on improving the security posture, the multi-tenant PnP Management Shell EntraID app has been deleted.”

https://github.com/pnp/powershell/discussions/4249

AADSTS700016 is an error code that indicates that the application you are trying to sign in to is not registered in Azure AD.

To fix this issue, you need to register the application in Azure AD.
Here are the steps to register an application in Azure AD:

  1. Open the Azure portal and sign in as a global administrator or
    co-admin.
  2. Select All services at the top of the navigation pane on the left
    side to open the Azure AD extension.
  3. Type Azure Active Directory in the filter search box, and then
    select Azure Active Directory.
  4. Select App registrations in the Azure AD navigation pane.
  5. Select New registration to register a new application.
  6. Enter a name for the application and select the supported account
    types.
  7. Select Register to create the application.

I would also suggest looking at this thread’s solution in case it applies to your case.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật