Skip to content

Instantly share code, notes, and snippets.

@MovGP0
Last active April 19, 2021 16:08
Show Gist options
  • Save MovGP0/7eba920d537138c119756478be6f3165 to your computer and use it in GitHub Desktop.
Save MovGP0/7eba920d537138c119756478be6f3165 to your computer and use it in GitHub Desktop.
Administrate IIS via Powershell
# source: https://adamtheautomator.com/powershell-iis/
New-Item -ItemType Directory -Name 'MyWebsite' -Path 'C:\inetpub\wwwroot';
New-IISSite `
-Name 'MyWebsite' `
-PhysicalPath 'C:\inetpub\wwwroot\MyWebsite';
New-IISSiteBinding `
-Name 'MyWebsite' `
-BindingInformation "*:443:" `
-CertificateThumbPrint "D043B153FCEFD5011B9C28E186A60B9F13103363" `
-CertStoreLocation "cert:\LocalMachine\Webhosting" ` # private key must be located here
-Protocol https;
# source: https://adamtheautomator.com/powershell-iis/
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
Install-PackageProvider -Name NuGet -Force
Install-Module -Name 'WebAdministration' -Scope AllUsers; # manage app pools
Install-Module -Name 'IISAdministration' -Scope AllUsers; # manage sites and binding
# source: https://adamtheautomator.com/powershell-iis-2/
# virtual folder to manage IIS
Set-Location IIS:\
# create app pool
New-Item -Path IIS:\AppPools\MyAppPool
Set-ItemProperty -Path IIS:\AppPools\MyAppPool -Name managedRuntimeVersion -Value '';
$newAppPool = New-WebAppPool -Name 'MyAppPool';
$newAppPool.AutoStart = "true";
# ...
$newAppPool | Set-Item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment