Skip to main content
formatting
Source Link

You can use my script to register app for 5 years (or more) just change New-MsolServicePrincipal command parameters.

   #Import-Module MSOnline [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")| Out-Null [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} function Install-SPOnlineApp { Param($appTitle,$appUrl,$clientID,$clientSecret,$appFileLocation) [Uri]$appUri = $appUrl $appDomain = $appUri.Host Write-Output "Installing app $appTitle on url $appUrl " #APP reg new online # required Windows Azure Active Directory Module for Windows PowerShell https://go.microsoft.com/fwlink/p/?linkid=236297 $servicePrincipalName = @("$clientID/$appDomain") $existing = Get-MsolServicePrincipal | where AppPrincipalId -EQ $clientId if($existing -eq $null) { New-MsolServicePrincipal -ServicePrincipalNames $servicePrincipalName -AppPrincipalId $clientID -DisplayName $appTitle -Type Symmetric -Usage Verify -StartDate $(Get-Date).AddDays(-1) -EndDate $(Get-Date).AddYears(5) -Addresses (New-MsolServicePrincipalAddresses -Address $appUrl) Start-Sleep -Seconds 5 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 } $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $pass = $AdminPassword | ConvertTo-SecureString -AsPlainText -Force $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUser , $pass) $ctx.Credentials = $credentials $sideLoadingEnabled = [Microsoft.SharePoint.Client.appcatalog]::IsAppSideloadingEnabled($ctx); $ctx.ExecuteQuery() if($sideLoadingEnabled.value -eq $false) { Write-Host "Enabling sideloading ..." $sideLoadingGuid = new-object System.Guid "AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D" $ctx.Site.Features.Add($sideLoadingGuid, $false, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null $ctx.ExecuteQuery() Write-Host "Sideloading enabled" } else { Write-Output "Sideloading was enabled" } $ctx.Web.LoadAndInstallApp([System.IO.File]::OpenRead($appFileLocation)) $ctx.ExecuteQuery() Write-Output "App installed in web $siteUrl"    }   

You can use my script to register app for 5 years (or more) just change New-MsolServicePrincipal command parameters.

  #Import-Module MSOnline [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")| Out-Null [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} function Install-SPOnlineApp { Param($appTitle,$appUrl,$clientID,$clientSecret,$appFileLocation) [Uri]$appUri = $appUrl $appDomain = $appUri.Host Write-Output "Installing app $appTitle on url $appUrl " #APP reg new online # required Windows Azure Active Directory Module for Windows PowerShell https://go.microsoft.com/fwlink/p/?linkid=236297 $servicePrincipalName = @("$clientID/$appDomain") $existing = Get-MsolServicePrincipal | where AppPrincipalId -EQ $clientId if($existing -eq $null) { New-MsolServicePrincipal -ServicePrincipalNames $servicePrincipalName -AppPrincipalId $clientID -DisplayName $appTitle -Type Symmetric -Usage Verify -StartDate $(Get-Date).AddDays(-1) -EndDate $(Get-Date).AddYears(5) -Addresses (New-MsolServicePrincipalAddresses -Address $appUrl) Start-Sleep -Seconds 5 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 } $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $pass = $AdminPassword | ConvertTo-SecureString -AsPlainText -Force $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUser , $pass) $ctx.Credentials = $credentials $sideLoadingEnabled = [Microsoft.SharePoint.Client.appcatalog]::IsAppSideloadingEnabled($ctx); $ctx.ExecuteQuery() if($sideLoadingEnabled.value -eq $false) { Write-Host "Enabling sideloading ..." $sideLoadingGuid = new-object System.Guid "AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D" $ctx.Site.Features.Add($sideLoadingGuid, $false, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null $ctx.ExecuteQuery() Write-Host "Sideloading enabled" } else { Write-Output "Sideloading was enabled" } $ctx.Web.LoadAndInstallApp([System.IO.File]::OpenRead($appFileLocation)) $ctx.ExecuteQuery() Write-Output "App installed in web $siteUrl"  }  

You can use my script to register app for 5 years (or more) just change New-MsolServicePrincipal command parameters.

  #Import-Module MSOnline [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")| Out-Null [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} function Install-SPOnlineApp { Param($appTitle,$appUrl,$clientID,$clientSecret,$appFileLocation) [Uri]$appUri = $appUrl $appDomain = $appUri.Host Write-Output "Installing app $appTitle on url $appUrl " #APP reg new online # required Windows Azure Active Directory Module for Windows PowerShell https://go.microsoft.com/fwlink/p/?linkid=236297 $servicePrincipalName = @("$clientID/$appDomain") $existing = Get-MsolServicePrincipal | where AppPrincipalId -EQ $clientId if($existing -eq $null) { New-MsolServicePrincipal -ServicePrincipalNames $servicePrincipalName -AppPrincipalId $clientID -DisplayName $appTitle -Type Symmetric -Usage Verify -StartDate $(Get-Date).AddDays(-1) -EndDate $(Get-Date).AddYears(5) -Addresses (New-MsolServicePrincipalAddresses -Address $appUrl) Start-Sleep -Seconds 5 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 } $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $pass = $AdminPassword | ConvertTo-SecureString -AsPlainText -Force $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUser , $pass) $ctx.Credentials = $credentials $sideLoadingEnabled = [Microsoft.SharePoint.Client.appcatalog]::IsAppSideloadingEnabled($ctx); $ctx.ExecuteQuery() if($sideLoadingEnabled.value -eq $false) { Write-Host "Enabling sideloading ..." $sideLoadingGuid = new-object System.Guid "AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D" $ctx.Site.Features.Add($sideLoadingGuid, $false, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null $ctx.ExecuteQuery() Write-Host "Sideloading enabled" } else { Write-Output "Sideloading was enabled" } $ctx.Web.LoadAndInstallApp([System.IO.File]::OpenRead($appFileLocation)) $ctx.ExecuteQuery() Write-Output "App installed in web $siteUrl"  } 
Source Link

You can use my script to register app for 5 years (or more) just change New-MsolServicePrincipal command parameters.

#Import-Module MSOnline [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")| Out-Null [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} function Install-SPOnlineApp { Param($appTitle,$appUrl,$clientID,$clientSecret,$appFileLocation) [Uri]$appUri = $appUrl $appDomain = $appUri.Host Write-Output "Installing app $appTitle on url $appUrl " #APP reg new online # required Windows Azure Active Directory Module for Windows PowerShell https://go.microsoft.com/fwlink/p/?linkid=236297 $servicePrincipalName = @("$clientID/$appDomain") $existing = Get-MsolServicePrincipal | where AppPrincipalId -EQ $clientId if($existing -eq $null) { New-MsolServicePrincipal -ServicePrincipalNames $servicePrincipalName -AppPrincipalId $clientID -DisplayName $appTitle -Type Symmetric -Usage Verify -StartDate $(Get-Date).AddDays(-1) -EndDate $(Get-Date).AddYears(5) -Addresses (New-MsolServicePrincipalAddresses -Address $appUrl) Start-Sleep -Seconds 5 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 } $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $pass = $AdminPassword | ConvertTo-SecureString -AsPlainText -Force $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUser , $pass) $ctx.Credentials = $credentials $sideLoadingEnabled = [Microsoft.SharePoint.Client.appcatalog]::IsAppSideloadingEnabled($ctx); $ctx.ExecuteQuery() if($sideLoadingEnabled.value -eq $false) { Write-Host "Enabling sideloading ..." $sideLoadingGuid = new-object System.Guid "AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D" $ctx.Site.Features.Add($sideLoadingGuid, $false, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null $ctx.ExecuteQuery() Write-Host "Sideloading enabled" } else { Write-Output "Sideloading was enabled" } $ctx.Web.LoadAndInstallApp([System.IO.File]::OpenRead($appFileLocation)) $ctx.ExecuteQuery() Write-Output "App installed in web $siteUrl" }