I need help finding a powershell script that would register my "Office365 SharePoint application" with Azure, i want to extract the Client ID from that script.
What I've tried (sorry for not mentioning the sources, i got these online):
try {
# Load the SharePoint snap in
$ver = $host | select version
if ($ver.Version.Major -gt 1) {
$host.Runspace.ThreadOptions = "ReuseThread"
}
if ((Get-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
[void][System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
} catch {
throw "A problem occured while loading DLLs: $_.Exception.Message"
}
The above code threw an error saying Microsoft.SharePoint.PowerShell does not exist on my machine.
And later I wanted to try this code, but obviously i did not because of the above error
function Register-App($siteCollection, $appFile, $appTitle) {
try {
$clientID = [guid]::NewGuid().ToString()
$web = Get-SPWeb -Identity $siteCollection
$realm = Get-SPAuthenticationRealm -ServiceContext $web.Site
$appIdentifier = $clientID + '@' + $realm
#Register the App with given ClientId
Register-SPAppPrincipal -DisplayName $appTitle -NameIdentifier $appIdentifier -Site $web | Out-Null
$app = Import-SPAppPackage -Path $appFile -Site $siteCollection -Source ObjectModel -Confirm:$false
#Install the App
Install-SPApp -Web $siteCollection -Identity $app | Out-Null
} catch {
throw "A problem occured while trying to register the app... $_.Exception.Message"
}
}
Any help would be appreciated; For dislikers, help improve this question.
Thanks