Привет друзья, меня зовут Ro8! В предыдущей статье мы с вами установили Windows Server 2008 R2 в режиме Server Core, в сегодняшней статье мы установим на Windows Server 2008 R2 (Server Core) средство автоматизации PowerShell 2.0.
Установка Windows PowerShell 2.0 на Windows Server 2008 R2 (Server Core)
В статье «Установка Windows Server 2008 R2 в режиме Server Core» мы установили на компьютер операционную систему Windows Server 2008 R2 в режиме Server Core.
После входа в систему перед нами появляется окно командной строки
Запустим Диспетчер задач введя в командной строке команду taskmgr
Откроется окно диспетчера задач
Выбираем «Новая задача».
Введем команду cmdи запустим еще один экземпляр командной строки
В итоге у нас есть два запущенных экземпляра командной строки
Перед тем, как выполнять установку Windows PowerShell, нам необходимо установить на компьютер компонент .net Framework 2.0
Для просмотра компонентов, доступных для установки выполним в первом экземпляре командной строки команду oclist
После выполнения команды oclist можно увидеть, что компонент .net Framework 2.0 (NetFx2-ServerCore)не установлен
Для установки компонента NetFx2-ServerCore воспользуемся командой ocsetup NetFx2-ServerCore(выполняем данную команду во втором экземпляре командной строки)
После того, как команда ocsetup NetFx2-ServerCore отработает, в первом экземпляре командной строки выполним команду oclist для просмотра установленных компонентов
Как видим, компонент NetFx2-ServerCore уже установлен
Таким же образом используя команду oclistвидим, что компонент MicrosoftWindowsPowerShell пока не установлен
Для установки компонента MicrosoftWindowsPowerShell выполним во втором экземпляре командной строки команду ocsetup MicrosoftWindowsPowerShell
Выполняем в первом экземпляре командной строки команду oclist и видим, что компонент MicrosoftWindowsPowerShell установлен
Перейдем по пути C:\Windows\System32\WindowsPowerShell\v1.0 выполнив команду cd Windows\System32\WindowsPowerShell\v1.0
Посмотрим содержимое папки v1.0 выполнив команду dir /b. Как видим, в папке v1.0 присутствует файл powershell.exe
Запустим файл powershell.exe, выполнив команду powershell.exe
Как видим, мы запустили экземпляр PowerShell, о чем свидетельствуют буквы PS
Выполним к примеру в PowerShell команду get-processдля просмотра процессов на данном компьютере
Problem
As we all know, Microsoft has announced support to run SQL Server on Windows Server 2008 R2 Server Core Edition which is GUI-less OS. In this tip I will explain the step by step process to install and enable PowerShell on a Windows 2008 R2 Server Core. PowerShell is basic prerequisite to install SQL Server on Windows Server 2008 R2 Server Core Edition. Check out this tip to get started with the PowerShell installation.
Solution
Based on the current build of Microsoft SQL Server 2012, it does not install or enable Windows PowerShell. However Windows PowerShell 2.0 is an installation prerequisite. If SQL Server setup reports that Windows PowerShell 2.0 is not present, you can install or enable it by below instructions on Windows Server 2008 R2 Server Core Edition.
Steps to enable PowerShell
Step 1 – Type “powershell” at the command prompt to find out if PowerShell is enabled or not. If PowerShell is enabled it will route you to the PS root directory. If PowerShell is not installed/enabled then Windows will not recognized this command.
As you can see in above screenshot, PowerShell is not enabled on this machine so our next step will be to enable it.
Step 2 – Run the “sconfig.cmd” command on your command prompt and press enter. Once you will press enter, it will open all of the options of system configuration as shown in the image below. The “sconfig.cmd” command is the Server Configuration Tool to configure and manage several common aspects of the Windows Server 2008 R2 Server Core installation. You must be a member of the Administrators group to use the tool.
You will be prompted to enter the number for the application which you want to configure. In our circumstances we will choose “4 (Configure Remote Management)” in order to enable PowerShell.
Step 3 – Once you have pressed “4” then press enter to see all of the options under the “Configure Remote Management” interface.
As you can see there are 5 options to choose from. The second option is for PowerShell. Choose option 2 in order to “Enable Windows PowerShell”.
Step 4 – After you type “2” and press enter, the PowerShell configuration will start and the configuration process will look like the below screenshot.
Step 5 – Once PowerShell has been successfully enabled, a separate command prompt screen will be pop-up and closed after the process reaches 100% completion. This is the deployment of features using the Dism.exe (Deployment Image Servicing and Management) tool. DISM enumerates, installs, uninstalls, configures and updates the features and packages in Windows images. See the screenshot below.
Step 6 – After all of the processes have completed, a restart window will appear and ask you to restart the machine in order for all of the changes to be committed. Click the “Yes” button to restart the machine.
Step 7 – Once the has been rebooted, type “powershell” on the command prompt. This time it will take few seconds to load then route you to a PS command prompt. You can run the “Get-Host” cmdlet to check the PowerShell version as shown in the screenshot below.
Next Steps
- At this point in time, you can proceed with your SQL Server installation. You can also enable PowerShell remoting which is a great feature of PowerShell 2.0 to manage your servers remotely from your local machine.
- Continue learning about PowerShell.
Posted by
on August 11, 2017
Windows Management Framework (WMF) 5.1 contains PowerShell 5.1. By default Windows Server 2008 R2 SP1 runs the older PowerShell version 2. By downloading and installing WMF 5.1 to a Windows Server 2008 R2 system, we can upgrade it to PowerShell version 5.1.
This post is part of our Microsoft 70-744 Securing Windows Server 2016 exam study guide series. For more related posts and information check out our full 70-744 study guide.
Download WMF 5.1 to a Windows Server 2008 R2 system
This also works with Windows Server 2012 and 2012 R2. By default Windows Server 2016 already has PowerShell 5.0 installed, so this is not required there. Note that to upgrade Windows Server 2008 R2 you must be using Service Pack 1 (SP1).
First we’ll confirm the verison of PowerShell on our 2008 R2 system. This can be done by opening PowerShell, and running $PSVersionTable, as shown below.
PS C:\> $PSVersionTable Name Value ---- ----- CLRVersion 2.0.50727.4927 BuildVersion 6.1.7600.16385 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1 PSRemotingProtocolVersion 2.1
As expected we have PowerShell version 2.0, which is the default in this operating system.
WMF 5.0 or higher is needed to provide the just-enough administration (JEA) PowerShell feature implemented in Windows Server 2016 into the older 2008 R2 SP1 operating system.
Before we download and install WMF though, we must first install .NET Framework 4.5.2 or later, as this is a prerequisite for WMF 5.1 in Windows Server 2008 R2 SP1, and by default 2008 R2 SP1 comes with .NET 3.5. You can download a newer version of .NET from here: https://www.microsoft.com/net/download/framework
After installation has completed you’ll need to perform a system reboot to proceed.
Next download Windows Management Framework (WMF) 5.1 from Microsoft: https://www.microsoft.com/en-us/download/details.aspx?id=54616
A system reboot is not required after installing WMF.
Once installed open PowerShell and run $PSVersionTable again, we can now see that PSVersion is listed as 5.1 as expected.
PS C:\> $PSVersionTable Name Value ---- ----- PSVersion 5.1.14409.1005 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.14409.1005 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1
We will now be able to configure our Windows Server 2008 R2 SP1 system to use just-enough administration (JEA), as we’ll cover in future posts.
Summary
By first updating the .NET Framework and then installing either WMF 5.0 or 5.1, we can upgrade our PowerShell version to support Just-Enough Administration (JEA) in older versions of Windows, such as Windows Server 2008 R2, 2012, and 2012 R2.
This post is part of our Microsoft 70-744 Securing Windows Server 2016 exam study guide series. For more related posts and information check out our full 70-744 study guide.
Reading Time: 2 minutes
Server Core installations of Windows Server 2008 R2 and installations of Hyper-V Server 2008 R2 offer Windows PowerShell. A lot has been written on the geekiness of PowerShell, how it wasn’t included in Server Core installations of Windows Server 2008 R2 and how you could enable it anyway. The question however is, how do you get started with using PowerShell in Server Core?
This blogpost shows you how to install PowerShell, how to start it up and issue some basic commands.
Installing PowerShell
To install Windows Powershell on a Server Core installation of Windows Server 2008 R2, issue the following three commands:
dism /online /enable-feature /featurename:NetFx2-ServerCore
dism /online /enable-feature /featurename:MicrosoftWindowsPowerShell
dism /online /enable-feature /featurename:ServerManager-PSH-Cmdlets
These commands will install the .Net Framework 2.0 binaries. This is a package, Windows PowerShell depends on. After you’ve successfully installed the .Net Framework you can install Windows PowerShell. Use the last command to be able to use the built-in PowerShell cmdlets for Server Manager.
Note:
The above commands are case sensitive.
If you also need 32bit support in Windows Powershell, also issue the following two (again: case sensitive) commands:
dism /online /enable-feature /featurename:NetFx2-ServerCore-WOW64
dism /online /enable-feature /featurename:MicrosoftWindowsPowerShell-WOW64
Tip!
You don’t need to install the base Windows on Windows (WoW) 64 package into a Server Core installation of Windows Server 2008 R2. This package is installed by default.
Starting PowerShell
To start using PowerShell you need to start it up. For some strange reason the path where PowerShell resides is not added to the %PATH% variable after installing, so you need to drill down to it, before you can start PowerShell.
Use the following commands:
cd C:Windowssystem32WindowsPowerShellv1.0
powershell
Now PowerShell is started. (Congratulations! 🙂 )
Showing off PowerShell
One of the strongest examples of the strength of PowerShell is the ability to add and remove Server Roles and Server Features, without the need to worry whether you’re typing them right. (remember, the dism.exe command is case-sensitive)
for instance, on the PowerShell you can use the following command to install the Windows on Windows (WoW) 64 support for .Net Framework 2.0:
PS > enable-windowsfeature netFX2-ServerCore-WoW64
Also, one of the nice benefit of using the get-windowsfeature PowerShell cmdlet is you get the hierarchy, instead of the long list of Server Roles and Features you get when you use dism /online /get-features. See for yourselves, when you execute the following command:
PS > import-module ServerManager
PS > get-windowsfeature
Further reading
Windows Server Core: Overview
Learning Windows Server 2008 R2 – Server Core…
Windows Server 2008 R2 Rocks!
How to enable PowerShell in Hyper-V Server 2008 R2
Setup Core Configurator on Windows Server 2008 R2
Using PowerShell on Windows Server 2008 R2 Server Core
Has Microsoft redeemed itself?
Sander Berkouwer is the author of the Active Directory Administration Cookbook, speaker and blogger at DirTeam.com and ServerCore.net. He is awarded Microsoft MVP, Veeam Vanguard and VMware vExpert.
Since 2009, Microsoft has awarded Sander with the Most Valuable Professional (MVP) award. Since 2016, Veeam has awarded Sander with the Veeam Vanguard award.
View all posts by Sander Berkouwer
[UPDATE] Instructions below are for Windows Server 2008 which does not have PowerShell or .NET support for Server Core. Windows Server 2008 R2 released later, has native support for these, so you can simply follow these Microsoft instructions to enable PowerShell there: http://support.microsoft.com/kb/976736
Below is a step-by-step instruction on installing Windows PowerShell on Windows Server 2008 in Server Core mode.
Note that these are in no way official or supported by Microsoft. Microsoft is working on official version of .NET and PowerShell for Server Core installations, so eventually you will be able to get this fully supported. Until then below are the instructions you can use at your own risk, etc., etc.
Quick Introduction
Windows Server 2008 has a command-line installation option – Server Core – which significantly reduces the attack surface and patch requirements by the virtue of not having Explorer and other UI components not needed in datacenter.
The problem is that it only ships with traditional cmd.exe and not PowerShell. To make things worse neither PowerShell nor .NET as they are today can be installed on such systems.
Below are the steps you can take to create packages of these tools which can be installed. Basically the whole procedure consists of just four main steps:
- Installing Visual C++ Redistributable Packages (required for .NET).
- Installing .NET 2.0 SP1
- Installing PowerShell.
- Jumping around the computer and shouting “I’ve got it!”
So let’s get started!
1. Visual C++ Redistributable Packages
This is the easiest one. All you need to do is download the packages you need:
- Microsoft Visual C++ 2005 SP1 Redistributable Package (x64)
- Microsoft Visual C++ 2005 SP1 Redistributable Package (x86)
After that, copy these files to your Server Core computer (e.g. using Robocopy) and simply run them there.
If your Server Core is 32-bit – just run vcredist_x86.exe
.
If it is 64-bit, you need to install both x86 and x64 versions (vcredist_x86.exe
and vcredist_x64.exe
).
2. .NET Framework
This is the most tricky part. PowerShell needs .NET 2.0 and .NET 2.0 is supposed to be a component of Windows Server 2008 so we will have to get a package of the framework which can get installed on such a system. To accomplish that we will:
- Download .NET Framework 3.5.
- Unpack the setup to get access to the .NET 2.0 Service Pack 1 installation files.
- Download and install the Orca MSI editor.
- Use Orca to remove the Windows version check.
- Run the updated MSI.
2.1. Download .NET: Go to Microsoft’s web site and download full redistributable package of .NET 3.5.
2.2. Unpack the file:
a. Create a folder c:\deploy
b. Save the downloaded .NET framework package to this folder.
c. Download the wonderful deploy.cmd script which Artem has posted and put it into the same folder.
d. Run the script.
After the script executes, the C:\Deploy\AIP
folder will have both NetFx20_x64
and NetFx20_x86
folders with .NET 2.0 framework files you need.
2.3. Install Orca:
This is great but unfortunately you cannot just install the files because the MSIs are specifically checking for Windows version. So now we need to disable this check. To do this we will use Microsoft’s Orca
MSI editor.
Note: This all needs to be done on a regular, not Server Core, machine. We will copy the results of our Orca operations to the Core box later on.
If you don’t have Orca, follow these steps to download it:
a. Download the Windows SDK for Windows Server 2008 and .NET Framework 3.5 installer.
b. Run the installer and deselect everything except Win32 Developer Tools
(this will make sure that you only download the few megs you need.)
c. After the installation completes, go to C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin
and install Orca.msi
.
2.4. Tweak the setup:
Now its time to do some patching.
a. Start Orca
and open the MSI you need (C:\Deploy\AIP\NetFx20_x86\NetFx20a_x86.msi
for 32-bit version or C:\Deploy\AIP\NetFx20_x64\NetFx20a_x64.msi
for x64).
b. Click Component.
c. In x86 locate: Regtlib.exe_Tool_____X86.3643236F_FC70_11D3_A536_0090278A1BB8
In x64 locate that one and Regtlib.exe_Tool_____A64.3643236F_FC70_11D3_A536_0090278A1BB8
d. Change the Condition from (VersionNT < 600) or Version9X
to just VersionNT or Version9X
.
e. Save changes (either to that same MSI or a transform file.)
2.5. Install .NET
Copy the files (the whole folder) to your core machine and start the MSI via this command line (note that you need to use msiexec in order to pass the vsextui=1
parameter):
If you saved a transformed file and are running 64-bit version you will probably run:
%SystemRoot%\system32\msiexec.exe /package "NetFx20_x64\NetFx20a_x64.msi" vsextui=1 transforms="ServerCore.mst"
On x86 without a transform that would be:
%SystemRoot%\system32\msiexec.exe /package "NetFx20_x86\NetFx20a_x86.msi" vsextui=1
That’s it. Now we have .NET installed and can go to the final step – PowerShell installation!
3. Windows PowerShell
There is no PowerShell v1 setup for Windows 2008 (again, because it is supposed to be a component) but you can actually download and install the CTP (note: this is a pre-beta code – not for production use). PowerShell v2 CTP2 is available from Microsoft’s downloads page.
Download the version you need, copy the msi over to the Server Core box and simply run the msi.
4. Enjoy!
Now you can start PowerShell!
Just run:
c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
And you will see the prompt change to: PS C:>
That’s it. Now you are among the first geeks in the Universe to have PowerShell on Server Core!
Acknowledgments: I could only have this all accomplished thanks to the help I got from Alex Kibkalo and a great post by Artem Pronichkin on installing .NET on Server Core.
Tags: PowerShell, PowerShell v2, Server Core, Windows Server 2008, hack