Import-Module WebAdministration $ErrorActionPreference = "Stop"; $appCmd = "$Env:SystemRoot\system32\inetsrv\appcmd.exe" function Test-DotNet-Hosting-Version-Installed { $dotNetCoreMinimumRuntimeVersion = [System.Version]::Parse("3.1.0.0"); $dotNetCoreMaximumRuntimeVersion = [System.Version]::Parse("4.0.0.0"); $DotNETCoreUpdatesPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates\.NET Core"; if (Test-Path $DotNETCoreUpdatesPath) { $DotNetCoreItems = Get-Item -ErrorAction Stop -Path $DotNETCoreUpdatesPath; $DotNetCoreItems.GetSubKeyNames() | Where-Object { $_ -Match "Microsoft .NET Core.*Windows Server Hosting" } | ForEach-Object { $registryKeyPath = Get-Item -Path "$DotNETCoreUpdatesPath\$_"; $dotNetCoreRuntimeVersion = $registryKeyPath.GetValue("PackageVersion"); $dotNetCoreRuntimeVersionCompare = [System.Version]::Parse($dotNetCoreRuntimeVersion); if ($dotNetCoreRuntimeVersionCompare -ge $DotNetCoreMinimumRuntimeVersion -And $dotNetCoreRuntimeVersionCompare -lt $dotNetCoreMaximumRuntimeVersion) { return $true; } } } return $false; } function Install-DotNet-Hosting { Write-Host "Installing dotnet hosting"; $tempDir = [System.IO.Path]::GetTempPath(); $downloadPath="$tempdir\netCoreHostingBundle.exe"; $DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy; $securityProtocol=@(); $securityProtocol+=[Net.ServicePointManager]::SecurityProtocol; $securityProtocol+=[Net.SecurityProtocolType]::Tls12; [Net.ServicePointManager]::SecurityProtocol=$securityProtocol; $WebClient=New-Object Net.WebClient; $Uri='https://download.visualstudio.microsoft.com/download/pr/bdc70151-74f7-427c-a368-716d5f1840c5/6186889f6c784bae224eb15fb94c45fe/dotnet-hosting-3.1.14-win.exe'; if ($DefaultProxy -And (-Not $DefaultProxy.IsBypassed($Uri))) { $WebClient.Proxy= New-Object Net.WebProxy($DefaultProxy.GetProxy($Uri).OriginalString, $True); }; $WebClient.DownloadFile($Uri, $downloadPath); $installArgs = New-Object -TypeName System.Collections.Generic.List[System.String]; $installArgs.Add("/quiet"); $installArgs.Add("/norestart"); Start-Process -FilePath $downloadPath -ArgumentList $installArgs -NoNewWindow -Wait -PassThru -WorkingDirectory $tempDir; } function Install-AppPool { Write-Host "Installing new application pool"; $Local:InstallationFolder = GetInstallationFolder; if ($Local:InstallationFolder -eq [string]::Empty) { Write-Host "Unable to detect installation folder"; return; } $Local:Enable32BitAppOnWin64 = GetEnable32BitAppOnWin64; New-Item iis:\AppPools\nShift -Verbose -Force; Set-ItemProperty IIS:\AppPools\nShift -Name "enable32BitAppOnWin64" -Value $Local:Enable32BitAppOnWin64 -Verbose; Get-WebSite -Name "Default Web Site" | Remove-WebSite -Confirm:$false; New-WebSite -Name ShipmentServer -PhysicalPath $Local:InstallationFolder -ApplicationPool nShift -Verbose -Force; Set-ItemProperty 'IIS:\Sites\ShipmentServer' -Name ApplicationPool -Value nShift -Verbose; Set-ItemProperty 'IIS:\AppPools\nShift' managedRuntimeVersion ""; $webHandlers = Get-WebHandler -PSPath "IIS:\Sites\ShipmentServer"; if (-Not ($webHandlers.Name -contains 'aspNetCore')) { New-WebHandler -Name 'aspNetCore' -Path * -Verb * -Modules 'AspNetCoreModuleV2' -PSPath "IIS:\Sites\ShipmentServer" -Verbose; }; & $appcmd set config ShipmentServer /section:handlers /accessPolicy:Read,Execute,Script /commit:apphost -Verbose; } function GetInstallationFolder { $Local:InstallationFolder = Get-ItemProperty -Path HKLM:\System\CurrentControlSet\Services\ConsignorServer | Select-Object -ExpandProperty ImagePath -ErrorAction Ignore; if ($null -ne $Local:InstallationFolder) { if (Test-Path -Path $Local:InstallationFolder -PathType Leaf) { $Local:InstallationFolder = Split-Path -Path $Local:InstallationFolder -Parent; return $Local:InstallationFolder; } } return [string]::Empty; } function Is64BitProcess { $shipmentServer = "ShipmentServer"; $consignorPath = (Get-Website $shipmentServer | Select-Object).PhysicalPath; $consignorExeFile = Join-Path -Path $consignorPath -ChildPath "Consignor.exe"; if (Test-Path -Path $consignorExeFile -PathType Leaf) { try { $fs = New-Object IO.Filestream($consignorExeFile, [Io.FileMode]::Open); $br = New-Object IO.BinaryReader($fs); if ($br.Readchar() -ne 'M') { return $false; } if ($br.Readchar() -ne 'Z') { return $false; } $fs.Seek(0x3c, [IO.SeekOrigin]::Begin) | Out-Null; $elfaw_new = $br.ReadUInt32(); $peheader = $fs.Seek($elfaw_new, [IO.SeekOrigin]::Begin); if ($br.Readchar() -ne 'P') { return $false; } if ($br.Readchar() -ne 'E') { return $false; } $mctypeoff = $fs.seek($peheader + 4, [IO.SeekOrigin]::Begin); $mctype = $br.ReadUInt16(); <# 0x0000 { "{0:x4} {1}" -f $mctype , "Unknown machine type"} 0x01d3 { "{0:x4} {1}" -f $mctype , "Matsushita AM33"} 0x8664 { "{0:x4} {1}" -f $mctype , "x64"} 0x01c0 { "{0:x4} {1}" -f $mctype , "ARM little endian"} 0x01c4 { "{0:x4} {1}" -f $mctype , "ARMv7 (or higher) Thumb mode only"} 0xaa64 { "{0:x4} {1}" -f $mctype , "ARMv8 in 64-bit mode"} 0x0ebc { "{0:x4} {1}" -f $mctype , "EFI byte code"} 0x014c { "{0:x4} {1}" -f $mctype , "Intel 386 or later family processors"} 0x0200 { "{0:x4} {1}" -f $mctype , "Intel Itanium processor family"} 0x9041 { "{0:x4} {1}" -f $mctype , "Mitsubishi M32R little endian"} 0x0266 { "{0:x4} {1}" -f $mctype , "MIPS16"} 0x0366 { "{0:x4} {1}" -f $mctype , "MIPS with FPU"} 0x0466 { "{0:x4} {1}" -f $mctype , "MIPS16 with FPU"} 0x01f0 { "{0:x4} {1}" -f $mctype , "Power PC little endian"} 0x01f1 { "{0:x4} {1}" -f $mctype , "Power PC with floating point support"} 0x0166 { "{0:x4} {1}" -f $mctype , "MIPS little endian"} 0x01a2 { "{0:x4} {1}" -f $mctype , "Hitachi SH3"} 0x01a3 { "{0:x4} {1}" -f $mctype , "Hitachi SH3 DSP"} 0x01a6 { "{0:x4} {1}" -f $mctype , "Hitachi SH4"} 0x01a8 { "{0:x4} {1}" -f $mctype , "Hitachi SH5"} 0x01c2 { "{0:x4} {1}" -f $mctype , "ARM or Thumb (`“interworking`”)"} 0x0169 { "{0:x4} {1}" -f $mctype , "MIPS little-endian WCE v2"} #> if ($mctype -eq 0x8664) { return $true; } return $false; } catch { return $false; } finally { $fs.close(); $fs.Dispose(); } }; } function GetEnable32BitAppOnWin64 { $Local:Is64BitProcess = Is64BitProcess; if ([Environment]::Is64BitOperatingSystem -And $Local:Is64BitProcess) { return "false"; } return "true"; } $isDotNetHostingInstalled = Test-DotNet-Hosting-Version-Installed; if(!$isDotNetHostingInstalled) { Install-DotNet-Hosting; } Install-AppPool;