I am installing a sharepoint hosted app on my sharepoint instance and it worked with no error.

Below is the script I used:

    [string]$Web = $(throw ‘- Need a SharePoint web site URL (e.g. "http://mysp15site/")’),
[string]$Source = "ObjectModel"

Write-Host -ForegroundColor White "——————-"
Write-Host -ForegroundColor White "| App Installer |"
Write-Host -ForegroundColor White "——————-"
Write-Host -ForegroundColor White "- "

#Global vars
$AppPackageName = "SharePointApp1.app";

#Loads powershell settings
Write-Host -ForegroundColor White "- Load Powershell context.."
$0 = $myInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)

#Loads the SharePoint snapin
Write-Host -ForegroundColor White "- Load SharePoint context.."
$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=, Culture=neutral, PublicKeyToken=71e9bce111e9429c") 

#Imports the App package
Write-Host -ForegroundColor White "- Import app package ‘$AppPackageName’…"
$appPath = $dp0 + "\" + $AppPackageName;
if ($Source.Equals("ObjectModel", [System.StringComparison]::InvariantCultureIgnoreCase)) {
$sourceApp = ([microsoft.sharepoint.administration.spappsource]::ObjectModel);
elseif ($Source.Equals("Marketplace", [System.StringComparison]::InvariantCultureIgnoreCase)) {
$sourceApp = ([microsoft.sharepoint.administration.spappsource]::Marketplace);
elseif ($Source.Equals("CorporateCatalog", [System.StringComparison]::InvariantCultureIgnoreCase)) {
$sourceApp = ([microsoft.sharepoint.administration.spappsource]::CorporateCatalog);
elseif ($Source.Equals("DeveloperSite", [System.StringComparison]::InvariantCultureIgnoreCase)) {
$sourceApp = ([microsoft.sharepoint.administration.spappsource]::DeveloperSite);
elseif ($Source.Equals("RemoteObjectModel", [System.StringComparison]::InvariantCultureIgnoreCase)) {
$sourceApp = ([microsoft.sharepoint.administration.spappsource]::RemoteObjectModel);

$spapp = Import-SPAppPackage -Path "$appPath" -Site $Web -Source $sourceApp -Confirm:$false -ErrorAction SilentlyContinue -ErrorVariable err;
if ($err -or ($spapp -eq $null)) 
Write-Host -ForegroundColor Yellow "- An error occured during app import !"
throw $err;
Write-Host -ForegroundColor White "- Package imported with success."

#Installs the App
Write-Host -ForegroundColor White "- Install the APP in web site…"
$app = Install-SPApp -Web $Web -Identity $spapp -Confirm:$false -ErrorAction SilentlyContinue -ErrorVariable err;
if ($err -or ($app -eq $null)) {
Write-Host -ForegroundColor Yellow "- An error occured during app installation !"
throw $err;
$AppName = $app.Title;
Write-Host -ForegroundColor White "- App ‘$AppName’ registered, please wait during installation…"
$appInstance = Get-SPAppInstance -Web $Web | where-object {$_.Title -eq $AppName};
$counter = 1;
$maximum = 150;
$sleeptime = 2;
Write-Host -ForegroundColor White "- Please wait…" -NoNewline;
while (($appInstance.Status -eq ([Microsoft.SharePoint.Administration.SPAppInstanceStatus]::Installing)) -and ($counter -lt $maximum))
Write-Host -ForegroundColor White "." -NoNewline;
sleep $sleeptime;
$appInstance = Get-SPAppInstance -Web $Web | where-object {$_.Title -eq $AppName} 
Write-Host -ForegroundColor White ".";

if ($appInstance.Status -eq [Microsoft.SharePoint.Administration.SPAppInstanceStatus]::Installed) {
Write-Host -ForegroundColor White "- The App was successfully installed.";
$appUrl = $appInstance.AppWebFullUrl;
Write-Host -ForegroundColor White "- The App is now available at ‘$appUrl’.";
Write-Host -ForegroundColor White  "- (Don’t forget to add app host name in your host file if necessary…).";
Write-Host -ForegroundColor White "- "
else {
Write-Host -ForegroundColor Yellow "- An unknown error has occured during app installation. Read SharePoint log for more information.";

But as soon as I try to open the app's site I get following error window from Chrome:

enter image description here

I cannot understand this error because there was no error in the PowerShell Script...

Does anyone know if I am missing something or if the script is not fully functional?

  • It seems like your isolated app domain is not configured properly. Try to add domain in host file. – Dikesh Gandhi Oct 7 '16 at 8:18
  • @DikeshGandhi and how can I add it to the file? – Snickbrack Oct 7 '16 at 8:21
  • 1
    press window+R and type DRIVERS and hit enter. under etc folder open the hosts file in notepad. Make an host entry for your server ip. – bkk Oct 7 '16 at 8:33
  • this is done by Visual Studio itself on my developing machine. If I deploy it with Visual Studio then the App is installed correctly and usable afterwards but if I use the above mentioned script on another machine then I get the above mentioned error. Is there a way to do the host-file insertion also programmatically via powershell? – Snickbrack Oct 7 '16 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.