What is PSRemoting or PowerShell Remoting and how to Enable PS Remoting

PSRemoting or PowerShell Remoting is a PowerShell based remoting which allows you to connect to one or thousands of remote computers and execute commands. PSRemoting allows you to sit at one place and execute commands on remote machine as if you are executing physically on the servers.

In this tutorial you will learn what is PS Remoting that is PowerShell Remoting and how to enable PowerShell Remoting locally and on remote machines.

Table of Content

  1. What is PSRemoting or PowerShell Remoting?
  2. Prerequisites
  3. How to Enable PS Remoting Locally on system?
  4. How to Enable PS Remoting on remote system?
  5. Conclusion

What is PSRemoting or PowerShell Remoting?

PowerShell Remoting is a feature of PowerShell. With PowerShell Remoting you can connect with a single or tons of servers at a single time.

WS-Management or Web services management or WS-Man provides a common way for systems to access and exchange management information across the IT infrastructure.

Microsoft implemented WS-Management or Web services management or WS-Man in WinRM that is Windows Remote Management that allows hardware and operating systems, from different vendors to connect to each other. For WinRM to obtain data from remote computers, you must configure a WinRM listener. WinRM listener can work on both HTTP or HTTPS Protocols.

When PowerShell Remoting takes place between two servers that is one server try to run commands remotely on other server, the source server connects to destination server on WinRM Listener.

How to check WinRM listeners on Windows Host?

To check the WinRM listeners on windows host use the following command

 winrm e winrm/config/listener

Prerequisites

  • Make sure you windows machine with PowerShell 7 installed . If you don’t have, Install it from here.

How to Enable PS Remoting Locally on system?

There are two ways in which you can enable PSRemoting on the local machine.

Use Enable-PSRemoting to Enable PS Remoting Locally on system

  • Invoke the command Enable-PSRemoting and this performs the following function
    • WinRM service is started
    • Creates listener on 5985 for HTTP
    • Registers and Enable PowerShell sessions
    • Set PowerShell sessions to allow remote sessions.
    • Restarts WinRM server

Enable-PSRemoting  # By Default its enabled in Windows
  • On a Server OS, like Windows Server 2019, the firewall rule for Public networks allows on remote connections from other devices on the same network. On a client OS, like Windows 10, you will receive an error stating that you are a public network.
Command Ran on Windows 2019 server
Command Ran on Windows 10 Machine
  • If you want to ignore the Error message because of Network Profile on client like windows 10 use the following command
Enable-PSRemoting -SkipNetworkProfileCheck

Use WinRM to Enable PS Remoting Locally on system

  • We can use WinRM quickconfig command as well to enable PS Remoting on local machine
winrm quickconfig

How to Enable PS Remoting on remote system?

There are two ways in which you can enable PSRemoting on the remote machine.

Use PS exec to Enable PS Remoting on remote system

  • Using PS exec you can run command on remote machine after connecting to remote machine. When you run PS exec command , it initialize the PowerShell session on remote machine and then run the command.
.\psexec.exe \\3.143.113.23 -h -s powershell.exe Enable-PSRemoting -Force # 3.143.113.23 is remote machine's IP address

Use WMI to Enable PS Remoting on remote system

Using PowerShell and the Invoke-CimMethod cmdlet. Using the Invoke-CimMethod cmdlet, you can instruct PowerShell to connect to the remote computer over DCOM and invoke methods.

$SessionArgs = @{
     ComputerName  = 'WIN-U22NTASS3O7'
     Credential    = Get-Credential
     SessionOption = New-CimSessionOption -Protocol Dcom
 }
 $MethodArgs = @{
     ClassName     = 'Win32_Process'
     MethodName    = 'Create'
     CimSession    = New-CimSession @SessionArgs
     Arguments     = @{
         CommandLine = "powershell Start-Process powershell -ArgumentList 'Enable-PSRemoting -Force'"
     }
 }
 Invoke-CimMethod @MethodArgs

Conclusion

In this tutorial, you have learned what is PSRemoting and how to enable PSRemoting with various methods locally on the machine as well as remotely on the machine. This will give you great opportunity to automate with various remote machines together.

Getting Started with PowerShell Commands which Every Devops should Know.

PowerShell is a strong tool which contains rich command utilities and commands which can make life easier for developers and Devops engineers. In this tutorial we will learn about important commands which are run on PowerShell with all practical’s to get you started with it.

Table of Content

  1. What is PowerShell ?
  2. Prerequisites
  3. Getting Started with PowerShell commands
  4. Wrapping Up

What is PowerShell ?

PowerShell is a command line tool or command line shell which helps in automation of various tasks , allows you to run scripts & helps you in managing variety of configuration. PowerShell runs on Windows , Linux and macOS

PowerShell is built on .NET Command Language Runtime that is ( CLR ) . It works currently on .NET 5.0 Framework as its runtime.

Features of PowerShell

  • It provides tab completion
  • It works with all .NET Frameworks objects
  • It allows pipelines of commands.
  • It has built support for various file formats such as JSON, CSV and XML

Prerequisites

Getting Started with PowerShell commands

PowerShell is a command line shell or command line tool or command line utility. There are tons of commands which are already loaded or in built in PowerShell and these commands are known as cmdlets.

  • There are majorly three types of command type in PowerShell
    • Alias
    • cmdlets
    • Function
  • To check the current version of PowerShell
$PSVersionTable
  • To check the execution policy of PowerShell
    • Restricted indicates that users are not allowed to run the scripts unless restrictions are removed.
Get-ExecutionPolicy
  • To Update the execution policy of PowerShell
    • This policy will allow users to run the Scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned    # Run as Administrator
  • To Check all the commands on PowerShell
Get-Command
  • To get help with command execution and about the command on Powershell
Get-Help
  • To check the status of Windows32 time service
Get-Service -Name w32time
  • To check the short form of PowerShell commands use Alias.
Get-Alias -Name gcm
Get-Alias -Name gm
  • To check the Folder structure and files under the folder.
 Get-ChildItem -Path C:\
  • To open system logs using PowerShell command
Show-EventLog
  • To check specific details of process such as chrome browser
 Get-Process chrome
  • To get content of a particular file
Get-Content .\.gitignore
  • To get drives in the current session
Get-PSDrive
  • To remove a particular file or folder using the following command.
Remove-Item .\date.txt

Wrapping up

This was pretty straightforward tutorial which covers basic PowerShell commands. We learnt majorly GET-command, GET-service command and different cmdlets which can be used with PowerShell. Hope this was useful tutorial to get you started with how to run commands on PowerShell.

How to Install PowerShell 7.1.3 on Ubuntu and Windows Machine Step by Step.

With some many windows or Linux Administrators in the world automation has always been top most requirement. PowerShell is one the most widely and command line shell which gives you string ability to perform any tasks with any remote operating system very easily.

In this tutorial we will go through basic definition of PowerShell, benefits and features of PowerShell and finally how to install latest PowerShell on both Windows and Ubuntu Machine.

Table of content

  1. What is PowerShell?
  2. Working with PowerShell
  3. Install PowerShell 7.1.3 on Windows Machine
  4. How to Install PowerShell 7.1.3 on Ubuntu Machine
  5. Conclusion

What is PowerShell?

PowerShell is a command line tool or command line shell which helps in automation of various tasks , allows you to run scripts & helps you in managing variety of configuration. PowerShell runs on Windows , Linux and macOS

PowerShell is built on .NET Command Language Runtime that is ( CLR ) . It works currently on .NET 5.0 Framework as its runtime.

Features of PowerShell

  • It provides tab completion
  • It works with all .NET Frameworks objects
  • It allows pipelines of commands.
  • It has built support for various file formats such as JSON, CSV and XML

Working with PowerShell

PowerShell is a command line tool or command line shell which was meant for windows automation . But it has widely grown and upgraded with lots of feature and benefits. Lets check out some of the key benefits.

  • PowerShell can be used for cloud management such as retrieve or deploy new resources.
  • PowerShell can be used with Continuous integration and continuous deployment pipelines i.e.. CI/CD
  • PowerShell is widely used now by Devops and sysops engineers.
  • PowerShell comes with hundreds of preinstalled commands
  • PowerShell command are called cmdlets

To check the version of PowerShell , although there are various command but lets run the following

$PSVersionTable.PSVersion

Install PowerShell on Windows Machine

By default PowerShell is already present on the windows machine. To verify click on start bar and look for PowerShell.

  • Verify the current version of PowerShell by running the following command.
Get-Host | Select-Object Version
  • Extract the downloaded binary on the desktop
  • Execute the pwsh.exe
  • Now you should see PowerShell version7.1.3 when you run the following command.
  • Lets verify PowerShell by invoking the Get-Command

How to Install PowerShell 7.1.3 on Ubuntu Machine

We will install PowerShell on ubuntu 18.04 via Package repository. So lets dive in here and start

  • Update the list of packages
sudo apt-get update
  • Install pre-requisite packages.
sudo apt-get install -y wget apt-transport-https software-properties-common
  • Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

he apt software repositories are defined in the /etc/apt/sources.list file or in separate files under the /etc/apt/sources.list.d/ directory.
  • Register the Microsoft repository GPG keys. You will notice that as soon as we run the below command a repository is added inside /etc/apt/source.list.d directory
sudo dpkg -i packages-microsoft-prod.deb
  • Update the Repository again
sudo apt-get update
  • Enable the “universe” repositories
sudo add-apt-repository universe
  • Install PowerShell
sudo apt-get install -y powershell
  • Start PowerShell
pwsh
  • Lets verify PowerShell by invoking the Get-Command

Conclusion

This tutorial is pretty straightforward and to get you started with PowerShell. In this tutorial we defined what is PowerShell and what are benefits of PowerShell. Later we Installed Latest PowerShell 7.1.3 on both ubuntu and windows machine. Hope this tutorial helps you with PowerShell setup & please share it if you like.