You'll need the MSOnline
module, which you can download from here (I have 1.1.166.0, 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"
Connect-MsolService
New-MsolServicePrincipal -ServicePrincipalNames $servicePrincipalName -AppPrincipalId $clientId -DisplayName $appName -Addresses (New-MsolServicePrincipalAddresses -Address $appUrl)
$bytes = New-Object Byte[] 32
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$rand.GetBytes($bytes)
$rand.Dispose()
$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: