📜 ⬆️ ⬇️

Setup of the screw web server without RDP

Just recently it took to set up a regular web server. Just at this time, I had a Spring aggravation of PowerShell. In general, as a small warm-up, I decided to set up a 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 configure a couple of websites. There are several options for how to do this remotely and from the command line, but today the sponsor will be PowerShell Remoting. In order for reality to become a reality, you need to enable PowerShell Remoting quite a bit.

Configuring PowerShell Remoting on the server


That's just here the first fail. It is difficult to turn on remote access when there is no remote access. In general, there will have to use RDP. In the PowerShell console (hereinafter simply the console), under the administrator, you need to run:

Enable-PsRemoting -Confirm

If everything is good, now there will always be PowerShell Remoting on the machine. At this point, RDP can be turned off. This rudiment of graphical interfaces is no longer needed. The next step is to configure the client.
')

Configuring PowerShell Remoting on Client


As for me, PowerShell wrote paranoids. Prohibited all that is possible and not possible. So it is also forbidden to connect to servers. This I am exaggerating a little bit If everything is in the same domain, then everything will be transparent. But in my situation, the machine is out of the domain and not even on the same network. In general, I decided that I would be careful and allow any extra-marital affairs.

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


That came to the most interesting. Connect to the server.

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

You can not imagine how I was waiting for this moment. Nervous, did not sleep the night. And then bang, and without drumming, I'm already on the command line on a machine somewhere on the other side of the earth. In general, yes. The most nervous stage we passed. We are on a remote machine. And very little is left.

IIS installation


Everything is simple:

Import-Module ServerManager
Add-WindowsFeature Web-Server


This will really put a lot of unnecessary stuff, so I would advise you to run Get-WindowsFeature, and install only the necessary features.

Installing .NET 4.0


And here is the file number two. There are no simple commands to install .NET 4.0. But there are some difficult. I will describe my version a little lower, and for reporting, I will briefly tell you about probably more correct. Microsoft has about a dozen of any "central" repositories. So for web servers there is a Web Platform Installer . And this thing has a Command Line interface. If you don’t ask yourself a question about installing WebPi Command Line, then installing .NET 4.0 would look like:

WebpiCmdline /Products: NETFX4RTM /AcceptEula

But back better to my version. If you solve the problem in the forehead, then these are two simple steps. Download the installer and run it from the command line. The main problem with the first step. There are no normal tools for downloading files in PowerShell. So I wrote a little module that wraps the .NET WebClient. True, I was waiting for a new problem. In order to install PsUrl, you need to download it. The circle is closed. But I was already unstoppable (aggravation). Feeling the strength to create another bike, I decided that it would be nice to have an installer of modules. Bums and the Internet have replenished with one more project .

Now the download issue is solved like this:

 #  PsGet (new-object Net.WebClient).DownloadString("https://github.com/chaliy/psget/raw/master/GetPsGet.ps1") | Invoke-Expression #  PsUrl install-module https://github.com/chaliy/psurl/raw/master/PsUrl/PsUrl.psm1 #  .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 #  .NET 4.0 start-process .\dotNetFx40_Full_x86_x64.exe -ArgumentList "/q /norestart" -Wait 


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

Customize sites


Import all you need:
Import-Module WebAdministration
On this server, all applications will be under .NET 4.0, therefore:

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

We will raise the test site:

 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.

Exit-PsSession

If anything, you can all one script . In general, I was more or less satisfied with the process. Fails are not so much. "Pitfalls" managed to get around. By the way, about the "pitfalls". There are many of them, I did not describe them in this topic, but if you have any problems, ask.

PS Spring aggravation continues.

[Upadate]

It turned out that I lied a little. Sorry. Downloading files in PowerShell is. And with the buns: download, asynchronous download, manager downloads and so on. Actually uses the Windows component - BITS. Microsoft traditionally lazhanul with the name therefore the module is called BitsTransfer.

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

Source: https://habr.com/ru/post/118020/


All Articles