Configuring a Windows web server without RDP

recently I needed to configure another web server. Just at this time I had spring fever PowerShell. In General, as a short workout, I decided to configure the web server without RDP.

So the task: there is a machine with Windows 2008 R2, which is somewhere in England, you need to install IIS .NET 4.0 and adjust a couple of websites. There are several ways to do this remotely from the command line, but today the sponsor will be PowerShell Remoting. To ensure that the true story became a reality, it is necessary very little, in fact, enable PowerShell Remoting.
/ >

setting up PowerShell Remoting on the server


Here's where the first fail. It is difficult to enable remote access when remote access is not. In General, there will have to use RDP. In the PowerShell console (just the console), the admin, need to perform:

the Enable-PsRemoting -Confirm

If all is well, now the car will always be PowerShell Remoting. This place RDP can be turned off. This vestige of graphical interfaces are no longer required. The next step is to configure the client.

setting up PowerShell Remoting on the client


As for me, PowerShell wrote paranoid. Forbidden all that is possible and not possible. Here to connect to the servers is also prohibited. Of course I exaggerate a little. If everything is in one domain, then everything will be transparent. But in my situation the machine outside the domain and not even in the same network. In General, I decided that I would tidy and will allow any extramarital Affairs.

set-item wsman:localhost\client\trustedhosts -value * -force
restart-service WinRm


That brings me to the most interesting. Connect to the server.

enter-pssession -ComputerName 192.0.32.10 -Credential "WS0114\Administrator"

You can't imagine how I've waited for this moment. Nervous night did not sleep. And then BAM, without the drums I have in the command line on a machine somewhere on the other end of the earth. In General, Yes. Most nervous stage we went through. We are on a remote machine. And left quite a bit.

Installing IIS


Everything is simple:

Import-Module ServerManager
Add-WindowsFeature Web-Server


It really put a bunch of junk, so I would advise to run the Get-WindowsFeature, and deliver only the desired features.

Installation .NET 4.0


And here is fail number two. Simple command to install .NET 4.0 yet. But there are a few difficult. Your option I will describe below, and for reporting, will briefly talk about is probably more correct. Microsoft there are a dozen sorts of "Central" repositories. And for web servers is Web Platform Installer. And this thing has Command Line interface. If you do not ask the installation of WebPi Command Line, then the installation .NET 4.0 would look like:

WebpiCmdline /Products: NETFX4RTM /AcceptEula

But back to my better option. If to solve the task in a forehead, it is a simple two step process. Download the installer and run it from the command line. The main problem with the first step. In PowerShell there are no normal tools for downloading files. So I wrote little module which wraps .NET WebClient. However, I waited for the new problem. In order to install PsUrl, it is necessary to download. The circle is closed. But I could not be stopped(relapse). Feeling the strength to create another bike, I decided that it would be nice to have the installer modules. Bums and the Internet added another project.

Now the question is download solved:

# Install PsGet
(new-object Net.WebClient).DownloadString("https://github.com/chaliy/psget/raw/master/GetPsGet.ps1") | Invoke-Expression
# Set PsUrl
install-module https://github.com/chaliy/psurl/raw/master/PsUrl/PsUrl.psm1
# Downloadable .NET 4.0
get-url http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe -ToFile dotNetFx40_Full_x86_x64.exe
# Installed .NET 4.0
start-process .\dotNetFx40_Full_x86_x64.exe -ArgumentList "/q /norestart" -Wait


Here it should be noted that PsUrl and PsGet is now in your modules, but they are not imported at the start of the profile.

Custom sites


The import all that is necessary:
Import-Module WebAdministration
On this server all applications will be under .NET 4.0, so:

Set-WebConfigurationProperty /system.applicationHost/applicationPools/applicationPoolDefaults -name managedRuntimeVersion -value v4.0

Raise test:

New-Item "C:\inetpub\example" -ItemType Directory
New-WebSite Example -Port:8080 -PhysicalPath:"C:\inetpub\example"
Get-Url http://example.com -ToFile "C:\inetpub\example\index.html"
Get-Url http://localhost:8080/


That's all.

the Exit-PsSession

If anything, you can still a script. In General, I process more or less satisfied. Feil not so much. Pitfalls managed to get around. By the way, about the "pitfalls". A lot of them, I did not describe them in this topic, but if you have problems, ask.

PS Spring fever continues.

[Upadate]

It turned out that I silent lie. Sorry. To download a file in PowerShell is. And with the buns: resuming asynchronous downloading, Manager downloads and so. Actually uses the Windows — BITS. Microsoft has traditionally made quite a mess with the name so the module called BitsTransfer.

Import-Module BitsTransfer
# Downloadable .NET 4.0
Start-BitsTransfer http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe
# Installed .NET 4.0
start-process .\dotNetFx40_Full_x86_x64.exe -ArgumentList "/q /norestart" -Wait
Article based on information from habrahabr.ru

Comments

Popular posts from this blog

Powershell and Cyrillic in the console (updated)

Active/Passive PostgreSQL Cluster, using Pacemaker, Corosync

Automatic deployment ElasticBeanstalk using Bitbucket Pipelines