Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

How to Remotely

Manage IIS Web


Server Using
PowerShell

https://msp360.com/
<How to Remotely Manage IIS Web Server Using PowerShell>

We’ve written about remotely managing your windows server in


a previous whitepaper, so I won’t go over the same material
again. Topics such as how to connect and make a session on
the server are all covered in the article ”How to remotely
manage your servers using PS remoting and invoke PowerShell
commands”.

What I did want to cover was, when all the remote management
is set up, what cmdlets are there in PowerShell that are
specific to the IIS web server? The answer is that there are a
vast number of cmdlets specific to IIS management in PowerShell
and that is what this article is about.

The IIS administration cmdlets that we will be discussing have


only existed since Server 2016 and IIS 10.0. Before this,
cmdlets used what was called web administration, which now
works side by side with the newer cmdlets. You can install the
latest IIS administration module via the PowerShell Gallery.

So, if you are remotely managing your IIS web server, you will
need to install the following module from your administration
workstation at an administrative PowerShell prompt:

Install-Module –Name IISAdministration

Then:

Import-Module IISAdministration

https://msp360.com/ 2 Page
<How to Remotely Manage IIS Web Server Using PowerShell>

First of all, let’s look at how to install IIS web server


using PowerShell:

Install-WindowsFeature -Name Web-Server -IncludeAllSubFeature


-ComputerName Server1

This cmdlet installs web server on Server1, and you will then
be able to start using the cmdlets.

How to view website status:

$SM = Get-IISServerManager $Sites = $SM.Sites $Sites

Name ID State Physical Path Bindings


---- -- ----- ------------- --------

Default Web Site 1 Stopped %SystemDrive%\inetpub\wwwroot http *:80:


Patti 2 Started C:\inetpub\Patti http *:8080:
http *:8033:

FTPSite 3 C:\inetpub\ftproot ftp *:21:


DavidChe 4 Started c:\ http *:8088:
MyNewSite 6555 Started C:\inetpub\wwwroot http *:8099:
http *:8022:

TestSite 5 Stopped C:\inetpub\testsite http *:8080:

This command uses a variable to store the return value from


the cmdlet Get-IISServerManager, then forms the object for
sites in another variable $SM.Sites and displays example sites
in IIS server manager. You can see if the status indicates
running or stopped, as well as the bindings for the site and
the default directory.

https://msp360.com/ 3 Page
<How to Remotely Manage IIS Web Server Using PowerShell>

Another way to view sites:

Get-IISSite
Name ID State Physical Path Bindings
---- -- ----- ------------- --------

Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:


PattiFul 2 Stopped C:\inetpub\PattiFul http *:8080:
http *:8033:

FTPSite 3 C:\inetpub\ftproot ftp *:21:

DavidChe 4 Started c:\ http *:8088:

MyNewSite 6555 Started C:\inetpub\wwwroot http *:8099:


http *:8022:

Running the Get-IISSite cmdlet will give a similar output to


that shown in the example.

How to create a new website on your server:

New-IISSite -Name ”TestSite” -BindingInformation ”*:8080:”


-PhysicalPath ”$env:systemdrive\inetpub\testsite”

This cmdlet makes a website named “TestSite” and assigns a


path and port.

How to create new bindings on a website:

New-IISSiteBinding -Name ”TestSite” -BindingInformation ”*:8080:”


-Protocol HTTP

This is an example of new bindings for the HTTP protocol for


the website TestSite.

https://msp360.com/ 4 Page
<How to Remotely Manage IIS Web Server Using PowerShell>

How to remove a website from the server:

Remove-IISSite -Name ”TestSite”

This removes the website TestSite.

If you want to remove bindings from a website:

Remove-IISSiteBinding -Name ”TestSite” -BindingInformation ”*:8080:”

How to start a website that is stopped:

Start-IISSite -Name ”Default Web Site”

This will start the default website.

If you want to stop a website:

Stop-IISSite -Name ”Default Web Site”

This cmdlet will stop your website.

How to view the app pool:

Get-IISAppPool
Name Status CLR Ver Pipeline Mode Start Mode
---- ------ ------- ------------- ----------

DefaultAppPool Started v4.0 Integrated OnDemand


.NET v4.5 Classic Started v4.0 Classic OnDemand
.NET v4.5 Started v4.0 Integrated OnDemand
PattiFul Stopped v4.0 Integrated OnDemand

You can see if an app pool is started on your IIS server.

https://msp360.com/ 5 Page
<How to Remotely Manage IIS Web Server Using PowerShell>

How to create a new virtual directory in IIS for your website:

IIS:\>New-WebVirtualDirectory -Site ”Default Web Site” -Name


ContosoVDir -PhysicalPath c:\inetpub\contoso

This creates the virtual directory ContosoVDir with the


indicated physical path for the website Default Web Site.

There are a whole host of other cmdlets available but these


are, in my opinion, some of the most popular. Also, these
cmdlets can be run directly on the server or remotely from
your administration workstation, with the proper configuration.

Once again, as you can see, these cmdlets will save you time
and effort and will minimize the administration tasks you will
have to do.

https://msp360.com/ 6 Page
<How to Remotely Manage IIS Web Server Using PowerShell>
PS C:\Users\

About MSP360

C:\>about MSP360

***************************************************
* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *
Established in 2011 by a group of experienced IT professionals,
MSP360™ (formerly CloudBerry Lab) provides cloud-based backup and
file management services to SMBs.

MSP360’s offerings include powerful, easy-to-use backup management


capabilities and military-grade encryption using customer-
controlled keys. Customers can choose to store their backup data
with all the major cloud storage providers, including Amazon S3,
Microsoft Azure, Google Cloud, Wasabi, and others. MSP360™ also
partners with thousands of VARs and MSPs to provide them with
turnkey, white-label data protection services.

***************************************************

Start a 15-day free trial or request a


personal demo of MSP360 Managed Backup
Service today: Learn More

https://msp360.com/ 7 Page

You might also like