I need to register a Provider hosted app in a site collection. It is possible to do it manually by using appregnew.aspx page. Is there anyway to do the same using C#/Powershell?

3 Answers 3


I fixed it myself. You can register the app in office 365 tenancy[SharePoint Online] using the below Azure AD MSOLService PS Script.

$newClientSecret = "p/zEuKBqkZRQsz6yRpOafj2f6zZdnQYvONatGWj0N0M=";
$appName="Your App Name"
$servicePrincipalName = @("$clientID/$appDomain")
$dtStart = [System.DateTime]::Now
$dtEnd = $dtStart.AddYears(10)

New-MsolServicePrincipal -ServicePrincipalNames $servicePrincipalName -AppPrincipalId $clientID -DisplayName $appName -Type Symmetric -Usage Verify -Value $newClientSecret -Addresses (New-MsolServicePrincipalAddresses -Address $appUrl) -StartDate $dtStart  –EndDate $dtEnd
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Sign -Value $newClientSecret -StartDate $dtStart  –EndDate $dtEnd
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $newClientSecret -StartDate $dtStart  –EndDate $dtEnd
  • Hi, is there any way to do this in C#/CSOM? Oct 10, 2018 at 14:58
  • There is no such option to do this using CSOM. Also, this does not come under SharePoint this is related to Azure AD.
    – Arut
    Oct 11, 2018 at 9:17
  • ok. Thanks. But it will create a new app principal in SharePoint Online right? Oct 11, 2018 at 10:13
  • 1
    Yes, it will create new app principal in SharePoint online as it is bonded to Azure AD.
    – Arut
    Oct 11, 2018 at 10:27
  • does this work for trusting an app on certain sharepoint site? thanks
    – Alberto S.
    Dec 27, 2019 at 14:17

Please read this link: Register SharePoint Add-ins

According to this link you can also Register the add-in through the Seller Dashboard. It's great option if you're going to use your add-in in more than one SharePoint tenant or farm. Publication in store is not required. This way you can choose a three-year valid secret key.


No, there is not, because the manual granting of consent is part of the app model architecture.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.