Is it possible to register app through PowerShell on SharePoint Online(Office 365)? i.e the conventional way where registering app data(Client Id, Client Secret..) is done on AppRegNew.aspx page.

I am aware that it can be done on On-Premises by using Register-SPAppPrincipal but it seems that Register-SPAppPrincipal is not supported on SharePoint Online.

How can we register app data on SharePoint Online via PowerShell?

1 Answer 1


You'll need the MSOnline module, which you can download from here (I have, I cannot say if this will work on an older version).

The following worked for me:

$clientId = [System.Guid]::NewGuid()
$appDomain = "HelloWorld.windowsazure.net"
$appName = "Hello World Test App"
$servicePrincipalName = @("$clientId/$appDomain")
$appUrl = "https://HelloWorld.windowsazure.net/Home/Index"


New-MsolServicePrincipal -ServicePrincipalNames $servicePrincipalName -AppPrincipalId $clientId -DisplayName $appName -Addresses (New-MsolServicePrincipalAddresses -Address $appUrl)

$bytes = New-Object Byte[] 32
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$clientSecret = [System.Convert]::ToBase64String($bytes)

New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Sign -Value $clientSecret
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Verify -Value $clientSecret
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $clientSecret

Write-Host "Client ID`t: $clientId`r`nClient Secret`t: $clientSecret"

I managed to scrounge this up from these sources:

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.