Internet Explorer is no longer supported. Many things will still work, but your experience will be degraded and some things won't function. Please use a modern browser such as Edge, Chrome, or Firefox.

Ensure Site

Ensures the existence of a site on a server.

Script usage:

IIS::Ensure-Site(
	Name: <text>,
	[AppPool: <text>],
	[Path: <text>],
	[BindingProtocol: <text>],
	[BindingAddress: <text>],
	[BindingHostName: <text>],
	[BindingPort: <integer>],
	[BindingCertficiate: <text>],
	[BindingCertificateStoreLocation: <integer>],
	[BindingCertificateHash: <text>],
	[BindingRequireSNI: <true/false>],
	[BindingCertificateStore: <text>],
	[Binding: <text>],
	[Bindings: <@(%(key1: value1, ...))>],
	[Exists: <true/false>]
);

Arguments:

NameFormatScript UsageUsage Notes
Name
text
Name
The unique name of the IIS site or application pool. This argument is required.
Application pool
text
AppPool
The name of the application pool assigned to the site.
Virtual directory physical path
text
Path
The path to the web site files on disk.
BindingProtocol
text
BindingProtocol
IP address
text
BindingAddress
Host name
text
BindingHostName
BindingPort
integer
BindingPort
SSL certificate
text
BindingCertficiate
Certificate store location
integer
BindingCertificateStoreLocation
SSL certificate hash
text
BindingCertificateHash
When specified, this value will be used to identify the SSL certificate by its thumbprint, and the "Certificate" and "CertificateStoreLocation" values will be ignored.
Require SNI
true/false
BindingRequireSNI
SSL certificate store
text
BindingCertificateStore
Binding
text
Binding
Multiple bindings (Legacy)
@(%(key1: value1, ...))
Bindings
This setting is no longer recommended; instead, use a separate operation to set multiple bindings. To enter multiple bindings, use a list of maps, e.g.:
@(%(IPAddress: 192.0.2.100, Port: 80, HostName: example.com, Protocol: http), %(IPAddress: 192.0.2.101, Port: 443, HostName: secure.example.com, Protocol: https, CertificateStoreName: WebHosting, CertificateHash: 51599BF2909EA984793481F0DF946C57E4FD5DEA, ServerNameIndication: true, UseCentralizedStore: false))
Exists
true/false
Exists

Note: When creating a site, you must specify binding information.

Example:


# ensures that the FooBar web site is present on the web server, and binds the site to the single IP address 192.0.2.100  and hostname "foorbar.corp"
IIS::Ensure-Site(
    Name: FooBar,
    AppPool: FooBarAppPool,
    Path: E:\Websites\FooBar,
    BindingProtocol: http,
    BindingAddress: 192.0.2.100,
    BindingHostName: foobar.corp
);

# ensures that the Default Web Site is removed from the web server
IIS::Ensure-Site(
    Name: Default Web Site,
    Exists: false
);