🚀 Welcome to MDriven Learn –  Don’t miss the latest Release Notes.
PowerShell script for IIS installation


MDriven Installation Scripts are PowerShell scripts that install and update MDriven Turnkey and MDrivenServer (.NET Core builds) on Windows with IIS. They can be used for one app at a time, or to install and update whole environments (Dev, Test, Production) from one settings file each.

Download: MDrivenInstallationScripts.zip (version 2026-11-13). The zip contains the folder MDriven Installation Scripts with all scripts, templates, examples and a detailed README.md.

(Please see this page for basic installation for .net core on Windows: MDrivenServerCore in IIS)

What the scripts do

  • Install or update one app – app pool, site, application, folder rights and program files from the Turnkey or MDrivenServer zip. A zip given by file name only is taken from your Downloads folder, or downloaded from MDriven if it is not there.
  • Install or update a whole environment – one MDrivenServer and any number of Turnkey apps, described in one settings file: stop them in the right order, install, write all settings files, connect the MDrivenServer to its SQL Server database, start them in the right order and check that each app answers.
  • Settings files from templates – CommandLineOverride.xml, MDrivenServerOverride.xml, TurnkeySettingsOverride.xml and HardServerUrl.xml are written into each app's App_Data from templates with {{values}}, so all installations are set up the same way and nothing is edited by hand on the server.
  • MDrivenServer connected to SQL Server without logging in – the connection string and server name are written directly into the MDrivenServer's local database (App_Data\DatabaseCompact.sdf). A new MDrivenServer can start from a prepared local database template.
  • Preview – shows what a deploy would do and compares every settings file it would write with the one the app has now, without changing anything.
  • Passwords kept out of the scripts – stored in clear text, encrypted, or in a secrets vault, and moved to safer storage when you are ready.
  • Safety – never unpacks a Turnkey zip over an MDrivenServer or the other way round, never overwrites files in App_Data, waits until app pools have really stopped and ends leftover processes, refuses broken zips, and says which process holds a file that cannot be replaced.

Requirements

  • Windows Server with IIS, the ASP.NET Core Hosting Bundle and the IIS feature IIS Management Scripts and Tools (PowerShell module IISAdministration).
  • Run the scripts in Windows PowerShell 5.1 as administrator.
  • PowerShell must be allowed to run the scripts – Windows blocks them by default. See below.
  • For https: a certificate in Cert:\LocalMachine\My with a friendly name.

Allow the scripts to run (PowerShell execution policy)

Windows does not run PowerShell scripts until you allow it. Windows 10/11 block all scripts by default, and Windows Server blocks scripts downloaded from the internet that are not signed – such as these. Without a change, PowerShell stops with "… cannot be loaded because running scripts is disabled on this system" or "… is not digitally signed". Do this once on the server:

  1. Unblock the zip before you unpack it: right-click MDrivenInstallationScripts.zip → Properties → tick Unblock → OK. Or in PowerShell, for files already unpacked:
Get-ChildItem 'C:\inetpub\MDrivenDeploy' -Recurse | Unblock-File
  1. Allow local scripts – in Windows PowerShell as administrator:
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
  1. RemoteSigned runs scripts on the computer itself and only demands a signature from scripts that come from the internet – which is why step 1 is needed.

Without changing the setting permanently, allow scripts only in the PowerShell window you are working in; it is reset when the window is closed:

Set-ExecutionPolicy Bypass -Scope Process

If the commands are refused because the policy is set by Group Policy, ask your Windows administrator. Read more: about Execution Policies (Microsoft).

NOTE! The certificate MUST be valid for the MDrivenServer to start. An MDrivenServer talks to itself and needs to be able to accept its own certificate.

IIS terms

  1. "Site" is the name of the website, which also points to the physical path on the server.
    • The site holds information on "bindings", which is to say which protocols and certificates should be used.
  2. A subfolder of a site usually looks like a "subsite" of a site, for example, of the "Default Web Site".
    • "Subsite" doesn't really exist, but can have application information assigned to it.
  3. "Application" is information stored in the site that points to an AppPool.
  4. "AppPool" is the settings for the process that will process requests of an Application.
  5. An application can be hosted in the site root, or in subfolders, i.e. subsites.

One app: CreateOrUpdateCoreSite.ps1

The script from the earlier version of this page, extended. It creates or updates one Turnkey app or MDrivenServer.

.\CreateOrUpdateCoreSite.ps1 -appName MDrivenServerTest -updateFile MDrivenServerCore_20261021.zip

Parameters:

  • appName – the name of the application and its app pool, and the URL path (https://server/appName). Also the site name if appInOwnSite is $true.
  • updateFile – the zip to install. A file name without path is looked for in the current user's Downloads folder and downloaded from MDriven if it is missing. Leave it out to only create or repair the IIS setup.
  • appType – Turnkey or MDrivenServer; guessed from the zip name. Used to refuse unpacking the wrong kind of zip over an app.
  • siteName – defaults to "Default Web Site".
  • appURL – the host name for the binding, used only when the site has to be created, e.g. app.company.com.
  • certFriendlyName – the friendly name of the certificate for the https binding, used only when the site has to be created. Without it the site gets an http binding.
  • appInOwnSite – $false (default) puts the app in siteName; $true gives the app its own site with the same name.
  • appInSiteRoot – $false (default) puts the app in a subfolder; $true makes it the site root.
  • inetpubPath – defaults to "%SystemDrive%\inetpub".
  • cleanSite – $true deletes the app's program files before unpacking. App_Data (settings and database) is always kept.
  • noStart – leave the app pool stopped at the end.

Whole environments

Keep the MDriven Installation Scripts folder unchanged, so a new version can simply replace it. Your own files go in a settings folder around it:

C:\inetpub\MDrivenDeploy\              your settings folder (any name)
    MDriven Installation Scripts\      the scripts from the zip, unchanged
    Environments\Dev1.psd1             one settings file per environment
    Environments\Test.psd1
    Templates\Turnkey\...              optional: your own templates
    Templates\MDrivenServer\DatabaseCompact.sdf   optional: your prepared local database
    Secrets\DeploySecrets.psd1         passwords (see below)

Steps:

  1. Copy Environment.example.psd1 from the scripts folder to Environments\Dev1.psd1 and fill in the site, the public and private addresses, the app names, the database and the versions to install. Every setting is explained in the file.
  2. Optional: put your own templates in Templates\Turnkey\ (for example with OpenID login turned on) and a prepared local database in Templates\MDrivenServer\DatabaseCompact.sdf. Without them the default templates from the scripts folder are used.
  3. Save the passwords once (see Passwords below).
  4. Preview, then run. All commands are run from the settings folder:
cd C:\inetpub\MDrivenDeploy
& '.\MDriven Installation Scripts\SaveDeploySecrets.ps1'
& '.\MDriven Installation Scripts\PreviewEnvironment.ps1' -configFile .\Environments\Dev1.psd1
& '.\MDriven Installation Scripts\CreateOrUpdateEnvironment.ps1' -configFile .\Environments\Dev1.psd1

Useful variations:

# Install a new build without editing the settings file
& '.\MDriven Installation Scripts\CreateOrUpdateEnvironment.ps1' -configFile .\Environments\Dev1.psd1 -turnkeyZip MDrivenTurnkeyCore_20261105.zip -serverZip MDrivenServerCore_20261105.zip

# Only re-apply settings files and database settings, e.g. after changing a template
& '.\MDriven Installation Scripts\CreateOrUpdateEnvironment.ps1' -configFile .\Environments\Dev1.psd1 -settingsOnly

# Update all environments in .\Environments, with a summary at the end
& '.\MDriven Installation Scripts\UpdateAllEnvironments.ps1' -turnkeyZip MDrivenTurnkeyCore_20261105.zip -serverZip MDrivenServerCore_20261105.zip

# Stop or start all apps of an environment in the right order
& '.\MDriven Installation Scripts\StopEnvironment.ps1' -configFile .\Environments\Dev1.psd1
& '.\MDriven Installation Scripts\StartEnvironment.ps1' -configFile .\Environments\Dev1.psd1

A deploy of an environment:

  1. reads the passwords,
  2. stops the Turnkey apps, then the MDrivenServer,
  3. installs each app (app pool, application, folder rights, program files),
  4. writes each app's settings files from the templates,
  5. writes the SQL Server connection string and server name into the MDrivenServer's local database,
  6. starts the MDrivenServer, then the Turnkey apps,
  7. calls each app once and reports whether it answers.

Public and private addresses

PublicBaseUrl is the address users see, for example a load balancer or reverse proxy. PrivateBaseUrl is how the server reaches the apps directly, for example http://appserver01. The apps get <base address>/<app name>. CommandLineOverride and MDrivenServerOverride use the private address; HardServerUrl and the OpenID redirect address use the public one. See HardServerUrl and MDrivenServerOverride.

Templates

Every file in a template folder is copied into the app's App_Data, with {{Name}} replaced by a value. The scripts provide EnvironmentName, AppName, DisplayName, AppPublicUrl, AppPrivateUrl, MDrivenServerUrl and ServerName; you add your own under Tokens and Secrets in the settings file. If a value is missing the script stops before anything is written. The settings files are rewritten at every deploy, so changes go in the templates; settings that only one installation needs belong in TurnkeySettingsExtra.xml, which the scripts never touch.

The MDrivenServer's local database

An MDrivenServer keeps its users, uploaded model and database settings in App_Data\DatabaseCompact.sdf. If Templates\MDrivenServer\DatabaseCompact.sdf exists, every new MDrivenServer starts with a copy of it – set up one MDrivenServer by hand once (password of user "a", a database connection), stop it and copy its .sdf there. An existing database is never replaced. At every deploy the scripts write the connection string from the settings file into the database, so the settings file decides which SQL Server database is used. The template database contains the server's users and passwords – treat it as a secret.

Passwords

The settings files only name each password with a key, for example SqlPassword = 'MDRIVEN_SQL_PASSWORD'. At deploy time each key is looked up in an environment variable with that name, then in a secrets vault (if one is named), then in the secrets file, and otherwise asked for in a hidden prompt. SaveDeploySecrets.ps1 saves them, and moves them to safer storage without retyping:

Level Command Who can read the passwords Good for
Clear text -protection Plain Anyone who can read the file (Administrators) A first trial on a server you trust
Encrypted for the server -protection Machine Any administrator on that server; a copy elsewhere is useless Recommended start – one or several people
Encrypted for one user -protection User Only that Windows account One fixed deploy account
A secrets system -vault <name> Whoever the vault allows (e.g. Azure Key Vault) Several people or servers, rotation, audit
& '.\MDriven Installation Scripts\SaveDeploySecrets.ps1' -protection Machine   # encrypt what is saved
& '.\MDriven Installation Scripts\SaveDeploySecrets.ps1' -list                 # storage level and saved names, never values

Troubleshooting

  • "The process cannot access the file ...\amd64\sqlceme40.dll because it is being used by another process" – a process has SQL Server Compact loaded from the MDrivenServer folder, and .NET cannot unload it until that process ends. The current scripts read the local database in a separate, short-lived process to avoid this; if it still happens, the error names the process that holds the file. With older versions of the scripts, close the PowerShell window and run again in a new one.
  • A settings file differs from what you expect – run PreviewEnvironment.ps1; it lists exactly which settings a deploy would change.

Earlier version

The single script that was on this page before is still available: File:CreateOrUpdateCoreSite.zip. CreateOrUpdateCoreSite.ps1 in the new package accepts the same parameters.