简体   繁体   中英

Powershell script to register SharePoint Online App with Azure

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

"Microsoft.SharePoint.PowerShell" available after you install the SharePoint 2013. After you install SharePoint 2013, applicable Windows PowerShell cmdlets are available in the SharePoint 2013 Management Shell.

More detail about SharePoint 2013 Management Shell, please refer to here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM