Register and Install App through PowerShell

Register App Client ID

$appDisplayName = "MyApp"
$clientID = "82ea34fc-31ba-4e93-b89a-aa41b023fa7e"

$targetWeb = ""
$authRealm = Get-SPAuthenticationRealm -ServiceContext $targetWeb
$AppIdentifier = $clientID + "@" + $authRealm
Write-Host "Creating the new app principal registration..."
Register-SPAppPrincipal -NameIdentifier $AppIdentifier -Site $targetWeb -DisplayName $appDisplayName
$appPrincipal = Get-SPAppPrincipal -Site $targetWeb -NameIdentifier $AppIdentifier

write-host "Display Name:" $appPrincipal.DisplayName
write-host "Name Identifier:" $appPrincipal.NameIdentifier

Install App

$spapp = Import-SPAppPackage -Path D:\ -Site –Source ObjectModel

$instance = Install-SPApp -Web -Identity $spapp

Grant App Permission (Trust)

$targetWeb = Get-SPSite ""
$clientID = "82ea34fc-31ba-4e93-b89a-aa41b023fa7e"
$authRealm = Get-SPAuthenticationRealm -ServiceContext $targetWeb 
$AppIdentifier = $clientID + "@" + $authRealm 
$appPrincipal = Get-SPAppPrincipal -Site $targetWeb.RootWeb -NameIdentifier $AppIdentifier 

Set-SPAppPrincipalPermission -Site $targetWeb.RootWeb -AppPrincipal $appPrincipal -Scope SiteCollection -Right FullControl

3 thoughts on “Register and Install App through PowerShell

  1. Thanks for one’s marvelous posting! I really enjoyed reading it, you will
    be a great author. I will remember to bookmark your blog and will eventually come back later on.

    I want to encourage yourself to continue your great writing, have a nice morning!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s