Running PowerShell scripts on Windows Server 2012 R2 can be a powerful way to automate various tasks and streamline your workflow. PowerShell is a command-line shell and scripting language developed by Microsoft, specifically designed for system administration. In this tutorial, we will guide you through the steps of running PowerShell scripts on Windows Server 2012 R2.
Step 1: Launch the PowerShell Console
Open the start menu and search for “Windows PowerShell.” Click on the PowerShell icon to launch the PowerShell console.
Step 2: Set Execution Policy
By default, the execution policy restricts running PowerShell scripts on a Windows Server. To enable script execution, you need to change the execution policy.
Type the following command in the PowerShell console and press Enter:
“`
Set-ExecutionPolicy RemoteSigned
“`
This command allows the execution of locally created scripts or signed scripts from trusted publishers.
Step 3: Navigate to the Script’s Location
Use the `cd` (Change Directory) command to navigate to the directory where your PowerShell script is located. For example, if your script is in the “C:Scripts” directory, type the following command:
“`
cd C:Scripts
“`
Step 4: Run the PowerShell Script
To run a PowerShell script, type the script’s filename with the “.ps1” extension and press Enter. For example, if your script is named “myscript.ps1,” type the following command:
“`
.myscript.ps1
“`
Press Enter to execute the script. The output of the script will be displayed in the PowerShell console.
Step 5: Execution Policy Changes (Optional)
After running the script, you may want to revert the execution policy to its original state for security reasons. To reset the execution policy to its default value, type the following command and press Enter:
“`
Set-ExecutionPolicy Restricted
“`
This command restores the default execution policy, which only allows the execution of PowerShell commands.
| Pros | Cons |
|---|---|
| 1. Allows automation and scripting of various tasks. | 1. Executing scripts without proper understanding can pose security risks. |
| 2. Provides greater control and flexibility compared to GUI-based tools. | 2. Writing scripts may require learning PowerShell syntax and commands. |
| 3. Scripts can be reused and shared across multiple machines. | 3. Debugging scripts can be more challenging compared to GUI-based tools. |
Video Tutorial: How to install PowerShell 2.0 on Windows Server 2012 R2?
Where is PowerShell in Windows Server 2012?
In Windows Server 2012, PowerShell is a powerful command-line shell and scripting language that is built on top of the .NET framework. Its primary function is to automate administrative tasks and provide a more efficient way to manage and control the server environment.
To locate PowerShell in Windows Server 2012, you can follow these steps:
1. Click on the “Start” button or press the Windows key on your keyboard to open the Start Menu.
2. In the Start Menu, locate the “Windows PowerShell” folder. It is usually found in the “Windows Administrative Tools” section. You can either scroll through the list or use the search bar to find it quickly.
3. Click on the “Windows PowerShell” folder to expand it.
4. Within the folder, you will find two options: “Windows PowerShell” and “Windows PowerShell ISE” (Integrated Scripting Environment). The former represents the standard PowerShell command-line interface, while the latter offers an enhanced scripting environment with additional features like syntax highlighting and debugging.
5. Choose the appropriate option depending on your needs. If you’re just starting with PowerShell, the standard command-line interface should suffice.
By following these steps, you will be able to locate and access PowerShell in Windows Server 2012, allowing you to leverage its powerful features for system administration and automation tasks.
How do I enable PowerShell script on server?
To enable PowerShell script on a server, you need to follow these steps:
1. Open PowerShell as an administrator: Right-click on the Start menu button and select “Windows PowerShell (Admin)” from the context menu.
2. Check the Execution Policy: Run the command `Get-ExecutionPolicy` to see the current execution policy. By default, it is likely set to “Restricted,” which prevents the execution of PowerShell scripts.
3. Change the Execution Policy: To allow script execution, run the command `Set-ExecutionPolicy RemoteSigned`. This execution policy only allows the execution of scripts signed by trusted publishers. However, it allows the execution of local scripts without requiring a digital signature.
4. Confirm the execution policy change: After setting the execution policy, run `Get-ExecutionPolicy` again to verify that it shows “RemoteSigned.”
5. Run PowerShell scripts: Now, you can run PowerShell scripts on the server. To execute a script, open PowerShell, navigate to the script’s location using the `cd` (change directory) command, and then run the script using its file name and extension (e.g., `.scriptName.ps1`).
By following these steps, you can enable the execution of PowerShell scripts on your server without any security or permission issues. However, always exercise caution when running scripts from untrusted sources or those you have not thoroughly reviewed.
Is PowerShell 5.0 is included with Windows Server 2012 R2?
Yes, PowerShell 5.0 is included with Windows Server 2012 R2. It was released as part of the Windows Management Framework (WMF) 5.0 update, which included updates to PowerShell, Windows Management Instrumentation (WMI), and the Server Manager CIM Provider.
Here are the steps to verify that PowerShell 5.0 is included with Windows Server 2012 R2:
1. Open the Start menu or press the Windows key on your keyboard.
2. Type “PowerShell” in the search bar and open the “Windows PowerShell” or “Windows PowerShell ISE” application.
3. Once the PowerShell console or ISE opens, type the following command and press Enter:
“`
$PSVersionTable.PSVersion
“`
4. The output will display the version of PowerShell installed on your system. If it shows as 5.0 or higher, then PowerShell 5.0 is included with Windows Server 2012 R2.
Note: PowerShell versions can also be checked from the “Programs and Features” section in the Control Panel of Windows Server 2012 R2. Look for “Windows Management Framework 5.0” or “Windows Management Framework 5.1” under the installed programs list to verify the installed version of PowerShell.
What version of PowerShell is available for Windows 2012 R2?
PowerShell is a powerful task automation and configuration management framework developed by Microsoft. When it comes to Windows Server 2012 R2, it includes a pre-installed version of PowerShell. Here’s the version information.
Windows Server 2012 R2 comes with PowerShell version 4.0 by default. PowerShell 4.0 introduced several new features and enhancements over its predecessor, such as Desired State Configuration (DSC), enhanced debugging capabilities, and improved language support.
To verify the installed PowerShell version on Windows Server 2012 R2, you can follow these steps:
1. Launch PowerShell: Click on the Start button or press the Windows key, type “PowerShell,” and click on “Windows PowerShell” from the search results.
2. Run the command: In the PowerShell window, type the following command and press Enter:
`$PSVersionTable.PSVersion`
This command will display the PowerShell version information, including the major version, minor version, build version, and revision.
Please note that while PowerShell version 4 is the default version on Windows Server 2012 R2, it is possible to upgrade PowerShell to a newer version manually if desired. However, this answer is based on the assumption that the server is running the default configuration without any additional updates or modifications.
To run a PowerShell script from the Command Prompt (cmd), you can follow these steps:
1. Open the Command Prompt: Press the Windows key, type “Command Prompt,” and click on the application when it appears in the search results.
2. Navigate to the directory containing the PowerShell script: Use the “cd” command to change the directory to where the script is located. For example, if the script is located in “C:Scripts,” type `cd C:Scripts` and press Enter.
3. Run the PowerShell script: Once you’re in the correct directory, you can execute the PowerShell script by entering the following command:
“`
powershell -File scriptname.ps1
“`
Replace “scriptname.ps1” with the actual name of your PowerShell script, including the file extension.
4. Press Enter to run the command, and the PowerShell script will execute.
By following these steps, you’ll be able to run PowerShell scripts directly from the Command Prompt, allowing you to automate various tasks or perform specific operations easily.
How to open PowerShell ISE in Windows Server 2012 R2?
To open PowerShell ISE (Integrated Scripting Environment) in Windows Server 2012 R2, you can follow these steps:
1. Launch the Start Menu: Click on the Windows logo located in the bottom-left corner of your screen or press the Windows key on your keyboard.
2. Search for PowerShell ISE: Begin typing “PowerShell ISE” in the search bar. As you type, the search results will start appearing.
3. Open PowerShell ISE: Once you see “Windows PowerShell ISE” in the search results, click on it to open the application.
Alternatively, you can also use the Run dialog box to open PowerShell ISE:
1. Press the Windows key + R on your keyboard simultaneously. This will open the Run dialog box.
2. In the Run dialog box, type “powershell_ise” (without quotes) and press Enter or click on the OK button.
By following these steps, you should be able to open PowerShell ISE on Windows Server 2012 R2.
{“@context”:”https://schema.org”,”@type”:”FAQPage”,”mainEntity”:[{“@type”:”Question”,”name”:”Where is PowerShell in Windows Server 2012?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”In Windows Server 2012, PowerShell is a powerful command-line shell and scripting language that is built on top of the .NET framework. Its primary function is to automate administrative tasks and provide a more efficient way to manage and control the server environment.nnTo locate PowerShell in Windows Server 2012, you can follow these steps:nn1. Click on the “Start” button or press the Windows key on your keyboard to open the Start Menu.nn2. In the Start Menu, locate the “Windows PowerShell” folder. It is usually found in the “Windows Administrative Tools” section. You can either scroll through the list or use the search bar to find it quickly.nn3. Click on the “Windows PowerShell” folder to expand it.nn4. Within the folder, you will find two options: “Windows PowerShell” and “Windows PowerShell ISE” (Integrated Scripting Environment). The former represents the standard PowerShell command-line interface, while the latter offers an enhanced scripting environment with additional features like syntax highlighting and debugging.nn5. Choose the appropriate option depending on your needs. If you’re just starting with PowerShell, the standard command-line interface should suffice.nnBy following these steps, you will be able to locate and access PowerShell in Windows Server 2012, allowing you to leverage its powerful features for system administration and automation tasks.”}},{“@type”:”Question”,”name”:”How do I enable PowerShell script on server?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”To enable PowerShell script on a server, you need to follow these steps:nn1. Open PowerShell as an administrator: Right-click on the Start menu button and select “Windows PowerShell (Admin)” from the context menu.nn2. Check the Execution Policy: Run the command `Get-ExecutionPolicy` to see the current execution policy. By default, it is likely set to “Restricted,” which prevents the execution of PowerShell scripts.nn3. Change the Execution Policy: To allow script execution, run the command `Set-ExecutionPolicy RemoteSigned`. This execution policy only allows the execution of scripts signed by trusted publishers. However, it allows the execution of local scripts without requiring a digital signature.nn4. Confirm the execution policy change: After setting the execution policy, run `Get-ExecutionPolicy` again to verify that it shows “RemoteSigned.”nn5. Run PowerShell scripts: Now, you can run PowerShell scripts on the server. To execute a script, open PowerShell, navigate to the script’s location using the `cd` (change directory) command, and then run the script using its file name and extension (e.g., `.scriptName.ps1`).nnBy following these steps, you can enable the execution of PowerShell scripts on your server without any security or permission issues. However, always exercise caution when running scripts from untrusted sources or those you have not thoroughly reviewed.”}},{“@type”:”Question”,”name”:”Is PowerShell 5.0 is included with Windows Server 2012 R2?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”Yes, PowerShell 5.0 is included with Windows Server 2012 R2. It was released as part of the Windows Management Framework (WMF) 5.0 update, which included updates to PowerShell, Windows Management Instrumentation (WMI), and the Server Manager CIM Provider.nnHere are the steps to verify that PowerShell 5.0 is included with Windows Server 2012 R2:nn1. Open the Start menu or press the Windows key on your keyboard.n2. Type “PowerShell” in the search bar and open the “Windows PowerShell” or “Windows PowerShell ISE” application.n3. Once the PowerShell console or ISE opens, type the following command and press Enter:n “`n $PSVersionTable.PSVersionn “`n4. The output will display the version of PowerShell installed on your system. If it shows as 5.0 or higher, then PowerShell 5.0 is included with Windows Server 2012 R2.nnNote: PowerShell versions can also be checked from the “Programs and Features” section in the Control Panel of Windows Server 2012 R2. Look for “Windows Management Framework 5.0” or “Windows Management Framework 5.1″ under the installed programs list to verify the installed version of PowerShell.”}},{“@type”:”Question”,”name”:”What version of PowerShell is available for Windows 2012 R2?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”PowerShell is a powerful task automation and configuration management framework developed by Microsoft. When it comes to Windows Server 2012 R2, it includes a pre-installed version of PowerShell. Here’s the version information.nnWindows Server 2012 R2 comes with PowerShell version 4.0 by default. PowerShell 4.0 introduced several new features and enhancements over its predecessor, such as Desired State Configuration (DSC), enhanced debugging capabilities, and improved language support.nnTo verify the installed PowerShell version on Windows Server 2012 R2, you can follow these steps:nn1. Launch PowerShell: Click on the Start button or press the Windows key, type “PowerShell,” and click on “Windows PowerShell” from the search results.n2. Run the command: In the PowerShell window, type the following command and press Enter:n `$PSVersionTable.PSVersion`nnThis command will display the PowerShell version information, including the major version, minor version, build version, and revision.nnPlease note that while PowerShell version 4 is the default version on Windows Server 2012 R2, it is possible to upgrade PowerShell to a newer version manually if desired. However, this answer is based on the assumption that the server is running the default configuration without any additional updates or modifications.”}},{“@type”:”Question”,”name”:”How to run PowerShell script from cmd?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”To run a PowerShell script from the Command Prompt (cmd), you can follow these steps:nn1. Open the Command Prompt: Press the Windows key, type “Command Prompt,” and click on the application when it appears in the search results.nn2. Navigate to the directory containing the PowerShell script: Use the “cd” command to change the directory to where the script is located. For example, if the script is located in “C:Scripts,” type `cd C:Scripts` and press Enter.nn3. Run the PowerShell script: Once you’re in the correct directory, you can execute the PowerShell script by entering the following command:nn “`n powershell -File scriptname.ps1n “`nn Replace “scriptname.ps1″ with the actual name of your PowerShell script, including the file extension.nn4. Press Enter to run the command, and the PowerShell script will execute.nnBy following these steps, you’ll be able to run PowerShell scripts directly from the Command Prompt, allowing you to automate various tasks or perform specific operations easily.”}},{“@type”:”Question”,”name”:”How to open PowerShell ISE in Windows Server 2012 R2?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”To open PowerShell ISE (Integrated Scripting Environment) in Windows Server 2012 R2, you can follow these steps:nn1. Launch the Start Menu: Click on the Windows logo located in the bottom-left corner of your screen or press the Windows key on your keyboard.n2. Search for PowerShell ISE: Begin typing “PowerShell ISE” in the search bar. As you type, the search results will start appearing.n3. Open PowerShell ISE: Once you see “Windows PowerShell ISE” in the search results, click on it to open the application.nnAlternatively, you can also use the Run dialog box to open PowerShell ISE:nn1. Press the Windows key + R on your keyboard simultaneously. This will open the Run dialog box.n2. In the Run dialog box, type “powershell_ise” (without quotes) and press Enter or click on the OK button.nnBy following these steps, you should be able to open PowerShell ISE on Windows Server 2012 R2.”}}]}
What is PowerShell?
Windows PowerShell is a command-line shell language interpreter and scripting language specifically designed for system administrators. It is similar to Bash Scripting in Linux. Built on the .NET Framework, Windows PowerShell helps IT professionals control and automate Windows operating system administration tasks as well as applications running on Windows Server environments.
PowerShell commands are called cmdlets, which allow computer management with the command line. The tools in PowerShell allow access to data warehouses such as Registry and Certificate Store as easily as accessing file systems.
In addition, PowerShell has a rich display parser and a fully developed scripting language. Simply put, you can complete all tasks like working with the user interface and more.
The PowerShell icon can be found in the taskbar and in the Start menu. You can open it by clicking on this icon.
When the screen below appears, Windows PowerShell is ready to work.
The latest version of PowerShell is 5.0 and to check which version of PowerShell is installed on the server, you only need to enter the command:
:$PSVersionTable
In the results returned, look for the PSVersion line in the Name column and look at the corresponding row in the Value column. As shown below, we see the version of PowerShell currently installed as 4.0.
To update to the latest PowerShell with more cmdlets, you must download Windows Management Framework 5.0 and install it.
Learn about PowerShell ISE
Windows PowerShell Integrated Scripting Environment (ISE) is a host application for Windows PowerShell. In PowerShell ISE, you can run the command line, write, test and debug scripts in a graphical user interface with multi-line editing, tab completion, syntax coloring, make selections, help contextual and support for right-to-left language.
You can use menu objects or keyboard shortcuts to perform many of the same tasks as you do in the Windows PowerShell console. For example, when debugging a script in PowerShell ISE, to set a line break in the script, simply right-click on the code, and select Toggle Breakpoint.
To open PowerShell ISE, just go to Start > Search > and enter PowerShell , in the search results that appear, you just need to click PowerShell ISE as shown:
The other way is to click the down arrow as shown below:
It will list all applications installed on the server and you just need to click on Windows PowerShell ISE.
PowerShell ISE interface will look like this:
It has 3 parts, 1 is PowerShell Console, 2 is Scripting File, 3 is Command Module. While creating the script, you can run it directly and see the result:
Basic commands in PowerShell
There are many PowerShell commands and it is difficult to list them all in this tutorial, we will only focus on PowerShell’s basic and most important commands.
The first is the Get-Help support command, explaining to you how to create commands and its parameters.
To get the update list, use the Get-HotFix command and to install a hot fix, say KB2894856, enter the following command: Get-HotFix -id kb2894856 .
Previous lesson: Install Role, configure role on Windows Server 2012
Running PowerShell v2 scripts on Windows 2012
This post will explain the procedure involved in enabling the PowerShell V2 engine in Windows 2012 server.
I got my Windows 2012 Server up today. As most of you already aware Windows 2012 comes with PowerShell V3 by default. So, that doesn’t mean that you have to upgrade all of your PowerShell V2 scripts to V3 version. There is a backward compatibility option available. But this is optional and not enabled by default. Follow the below steps to enable the backward compatibility by installing PowerShell v2 engine.
- Open Server Manager
- Click on Add Roles or Features
- Select “Role-Based or Feature-Based installation” on Installation Type page
- In the server selection section, make sure that local server is selected
- Click next on “Server Roles” page without selecting any
- On “Features” page, expand “Windows PowerShell (Installed)” and select “Windows PowerShell 2.0 Engine” as shown below
- Upon selecting the option you will see another prompt like below to install the required pre-requisites.
- Click “Add Features to Continue
- On the “Confirm Installation Selections” page, click Install. The installation may requires media, so ensure that it is available.
- Installation will take a while and be patient.
- This completes the installation.
Launching the PowerShell V2 Console on Windows 2012:
You can use the below command to launch PowerShell V2 and you can run your Powershell V2 scripts from this console. You may verify the version of this console by using Get-Host cmdlet.
powershell.exe -version 2
Hope this helps…
Installing And Configuring Windows Server 2012 Pdf Active Directory Install and configure windows server 2012. describe ad ds infrastructure, and install and configure domain controllers. manage ad ds objects. automate ad ds administration. describe internet protocol version 4 (ipv4) addressing. • perform post ‑installation configuration of windows server 2012. • describe the management tools available in windows server 2012. • perform basic administrative tasks using windows powershell.
Installing And Configuring Windows Server 2012 R2 Pdf Hyper V Edge necessary to implement a core windows server 2012 r2 infrastructure into an existing enterprise environment. this book covers the initial implementation and configuration of the windows server 2012 r2 core services, such as active directory and the networking services. Most of the features in windows server provide support for windows powershell® by including modules that enable you to install, configure, and use the feature at a windows powershell prompt in addition to the traditional graphical user interface. Understand and perform the installation of windows server 2012 r2, including server core and server with a gui configurations. learn to manage windows server 2012 using both traditional management tools and automation with windows powershell. Perform post‑installation configuration of windows server 2012. describe the management tools available in windows server 2012. perform basic administrative tasks using windows powershell.
Installation Of Windows Server 2012 Pdf Operating System Technology Understand and perform the installation of windows server 2012 r2, including server core and server with a gui configurations. learn to manage windows server 2012 using both traditional management tools and automation with windows powershell. Perform post‑installation configuration of windows server 2012. describe the management tools available in windows server 2012. perform basic administrative tasks using windows powershell. Windows powershell® web access, first introduced in windows server® 2012, acts as a windows powershell gateway, providing a web based windows powershell console that is targeted at a remote computer. It provides an overview of windows server 2012 and windows server 2012 management. installing windows server 2012, post installation configuration of windows server 2012 and introduction to windows powershell are also covered. Perform post‐installation configuration of windows server 2012. describe the management tools available in windows server 2012. perform basic administrative tasks using windows powershell. module 2: introduction to active directory domain services. Introduction. powershell continues to improve, many features are being added and now we have powershell 5 that is available for installation on windows server 2012 and windows 8.1. the installation is simple and only requires a reboot.
Installation Of Windows Server 2012 R2 Pdf Microsoft Windows Booting Windows powershell® web access, first introduced in windows server® 2012, acts as a windows powershell gateway, providing a web based windows powershell console that is targeted at a remote computer. It provides an overview of windows server 2012 and windows server 2012 management. installing windows server 2012, post installation configuration of windows server 2012 and introduction to windows powershell are also covered. Perform post‐installation configuration of windows server 2012. describe the management tools available in windows server 2012. perform basic administrative tasks using windows powershell. module 2: introduction to active directory domain services. Introduction. powershell continues to improve, many features are being added and now we have powershell 5 that is available for installation on windows server 2012 and windows 8.1. the installation is simple and only requires a reboot.
Installing And Configuring Windows Server 2012 It Opsec Perform post‐installation configuration of windows server 2012. describe the management tools available in windows server 2012. perform basic administrative tasks using windows powershell. module 2: introduction to active directory domain services. Introduction. powershell continues to improve, many features are being added and now we have powershell 5 that is available for installation on windows server 2012 and windows 8.1. the installation is simple and only requires a reboot.
Windows Server 2012 Training Course Installation Configuration
Enabling Windows PowerShell v2.0 Windows Server 2012 R2
In this Post I will go through the steps of Installing PowerShell V 2.0 on windows Server 2012 R2.
The following prerequisites needs to be configured before installing PowerShell V 2.0.
On Windows Server 2012 R2 and Windows Server 2012
Use the following procedures to add the Windows PowerShell 2.0 Engine and Microsoft .NET Framework 3.5 features. The Windows PowerShell 2.0 Engine requires Microsoft .NET Framework 2.0.50727 at a minimum. This requirement is fulfilled by Microsoft .NET Framework 3.5.
To add the .NET Framework 3.5 feature
In Server Manager, from the Manage menu, select Add Roles and Features.
Or in Server Manager, click All Servers, right-click a server name, and then select Add Roles and Features.
On the Installation Type page, select Role-based or feature-based installation.
On the Features page, expand the .NET 3.5 Framework Features node and select .NET Framework 3.5 (includes .NET 2.0 and 3.0).
The other options under that node are not required for the Windows PowerShell 2.0 Engine.
To add the Windows PowerShell 2.0 Engine feature
In Server Manager, from the Manage menu, select Add Roles and Features.
Or Server Manager, click All Servers, right-click a server name, and then select Add Roles and Features.
On the Installation Type page, select Role-based or feature-based installation.
On the Features page, expand the Windows PowerShell (Installed) node and select Windows PowerShell 2.0 Engine.
For information about starting the Windows PowerShell 2.0 Engine, see Starting the Windows PowerShell 2.0 Engine.
Lets have a look at enabling PowerShell v2.0 using PowerShell 🙂 .
Run PowerShell as Administrator and type the below cmdlets.
|
Install-WindowsFeature Powershell-V2 |
#ThatLazyAdmin
