Create a website and add a certificate with powershell

Import-Module WebAdministration

# Create the new website
New-Website -Name DemoSite -PhysicalPath C:\inetpub\wwwroot\


# Notice all web bindings created
Get-WebBinding

# Find the bindings only on the website we just created
(Get-Website -Name 'DemoSite').bindings.Collection

# Add a new binding to the site bound to all IP address for our SSL connection
New-WebBinding -Name 'DemoSite' -IPAddress * -Port 443 -Protocol https

# Notice the bindings now
(Get-Website -Name 'DemoSite').bindings.Collection

# Create a self-signed certificate assigning it to a variable to use in the next step
$cert = New-SelfSignedCertificate -CertStoreLocation 'Cert:\LocalMachine\My' -DnsName 'demosite.spacecowboy.local'

# Attach the certificate to the SSL binding
$certPath = "Cert:\LocalMachine\My\$($cert.Thumbprint)"
$providerPath = 'IIS:\SslBindings\0.0.0.0!443' ## Binding to all IP address and to port 443
Get-Item $certPath | New-Item $providerPath