PowerShell – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Fri, 03 Jun 2022 05:31:27 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Install PowerShell on Fedora https://tecadmin.net/how-to-install-powershell-on-fedora/ https://tecadmin.net/how-to-install-powershell-on-fedora/#respond Thu, 03 Mar 2022 10:09:13 +0000 https://tecadmin.net/?p=28662 PowerShell is an command line interface as well as a scripting language developed by Microsoft. Similar to bash programing, the PowerShell is also used for automating the jobs for the system management. The current version of PowerShell supported Fedora 32 or greater versions. PowerShell is also available for the Linux systems with an official package [...]

The post How to Install PowerShell on Fedora appeared first on TecAdmin.

]]>
PowerShell is an command line interface as well as a scripting language developed by Microsoft. Similar to bash programing, the PowerShell is also used for automating the jobs for the system management. The current version of PowerShell supported Fedora 32 or greater versions.

PowerShell is also available for the Linux systems with an official package repository. This tutorial will help you for installing PowerShell on Fedora Linux system.

Prerequisites

You must be login as root account or sudo privileged account to your Fedora Linux system.

Enable Microsoft Repository in Fedora

First of all add the Microsoft signature key to your Fedora system by running the following command.

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc 

Next, execute the following command to add the Microsoft repository to the Fedora system

sudo rpm -Uvh https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm 

Install PowerShell in Fedora

Now run the ‘dnf check-update’, which update the metadata of all enabled repositories. This will not actually update the packages but list all packages.

sudo dnf check-update 

Now, You are prepared to install PowerShell on Fedora system. Run the below command to install PowerShell on Fedora Linux system.

sudo dnf install powershell 
How to Install PowerShell on Fedora Linux
Installing PowerShell on Fedora Linux

That’s it. This will complete the PowerShell installation on your Fedora system.

Access PowerShell in Fedora

To access the PowerShell terminal, type pwsh on a terminal. On successful, you will get the Powershell terminal as below.

pwsh 
How to Install PowerShell on Fedora Linux
Connect to PowerShell

After getting the prompt, type “help” to get detailed information about uses.

How to Uninstall PowerShell on Fedora

If you don’t need PowerShell anymore on your system. Simply type below command to uninstall it.

sudo dnf remove powershell

Conclusion

This guide helped you for installing PowerShell on Fedora Linux system. Now you can use PowerShell features to administer your server and automate the tasks.

The post How to Install PowerShell on Fedora appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-install-powershell-on-fedora/feed/ 0
How to Check Computer Uptime in Windows https://tecadmin.net/check-computer-uptime-in-windows/ https://tecadmin.net/check-computer-uptime-in-windows/#respond Wed, 04 Aug 2021 09:43:02 +0000 https://tecadmin.net/?p=27024 Computer Uptime refers to how long a system has been up and running without any shutdown or restart. The computer uptime helps us to find the last reboot of any system. This can be helpful in many ways like troubleshooting or scripting etc. In this tutorial, we will discuss three ways to check the uptime [...]

The post How to Check Computer Uptime in Windows appeared first on TecAdmin.

]]>
Computer Uptime refers to how long a system has been up and running without any shutdown or restart. The computer uptime helps us to find the last reboot of any system. This can be helpful in many ways like troubleshooting or scripting etc. In this tutorial, we will discuss three ways to check the uptime of any Windows machine or server.

1. How to Check Windows Uptime with Task Manager

A task manager is a computer program used for checking the process and services running and their details. You can also find details about the resource utilization like Memory and CPU uses at runtime. This is also a quick and preferred way for Windows users to find computer uptime.

  1. Log in to your Windows system.
  2. Right click on task bar and click on Task Manager to launch.
  3. Click “More details”, If the task manager opened in compact view.
  4. Go to Performance tab
  5. In CPU section, you will find computer uptime like below screenshot

Check Computer Uptime in Task Manager

As per the above screenshot, this computer is up from 33 Days and 33 minutes.

2. Check Computer Uptime with Command Prompt

You can also find the Windows uptime with the command-line options. Here we will discuss the two commands that provide the uptime details.

A. Using WMIC Command:

WMIC (Windows Management Interface Command), is a simple command-line utility that provides information about the running system. With the help of this command, we can find the last boot-up time.

wmic path Win32_OperatingSystem get LastBootUpTime

Check Computer Uptime in Command Prompt

B. Using systeminfo Command:

The systeminfo command displays a list of details about your operating system, computer software, and hardware components. You can also check for the value “System Boot Time” to get the computer uptime.

systeminfo | find "System Boot Time"

Check Windows Uptime in Command Prompt

3. How to Check Windows Uptime with PowerShell

Launch a Powershell window and type the below command to find the last reboot time of the current system.

Get-CimInstance -ClassName Win32_OperatingSystem | Select LastBootUpTime

Check Computer Uptime in PowerShell

You can also view the computer uptime in the number of days, hours, and minutes formats. Execute the below command and check the results.

(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime

Check Windows Uptime in PowerShell

You can also store the output of the above commands to a variable. Which can be helpful for scripting purposes. The below command will store all values in the “uptime” variable.

$uptime = (get-date) - (gcim Win32_OperatingSystem).LastBootUpTime

Next, extract the specific values only and print them on the screen.

Write-Output "The Windows Uptime is >> $($uptime.days) Days, $($uptime.Hours) Hours and $($uptime.Minutes) Minutes"
Output:
The Windows Uptime is >> 35 Days, 12 Hours and 46 Minutes

Conclusion

In this tutorial, you have learned various methods for checking Windows uptime. This guide covers the 3 methods like Task manager, command prompt, and PowerShell to get computer uptime.

The post How to Check Computer Uptime in Windows appeared first on TecAdmin.

]]>
https://tecadmin.net/check-computer-uptime-in-windows/feed/ 0
Which Process is Listening on a Port in Windows https://tecadmin.net/which-process-is-listening-on-a-port-in-windows/ https://tecadmin.net/which-process-is-listening-on-a-port-in-windows/#comments Wed, 28 Oct 2020 15:27:07 +0000 https://tecadmin.net/?p=23367 How do I find, which process is listening on a specific port on the Windows operating system? This article will help you to find the process name listening on a specific port on a Windows system. Sometimes you may have faced issues like “port in use” during application installation. You can choose one of the [...]

The post Which Process is Listening on a Port in Windows appeared first on TecAdmin.

]]>
How do I find, which process is listening on a specific port on the Windows operating system?

This article will help you to find the process name listening on a specific port on a Windows system. Sometimes you may have faced issues like “port in use” during application installation.

You can choose one of the below given 2 methods. The first method uses netstat to find the PID of the process listening on a specific port, then use tasklist to find the process name by the PID.

Method 1. Using Default Command Prompt

Use the following command to find out the process id (PID) listening on port 80. You can change this port to search for another port.

netstat -aon | findstr ":80" | findstr "LISTENING" 
Output:
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4 TCP [::]:80 [::]:0 LISTENING 4

The last column of the output shows the PID of the processes. The above output shows the PID is 4 for the process listening on port 80.

Use this process id with the task list command to find the process name.

tasklist /fi "pid eq 4" 

You will see the process name in the results.

Which Process is Listening on a Port in Windows
Finding the process listening on specific port in Windows

Method 2. Using Get-Process in PowerShell

The second method uses the PowerShell command to find out the process running on a specific port on Windows.

Launch the PowerShell terminal and execute the following command to find the process name running on port 80. You can change the port number to check for other ports.

Get-Process -Id (Get-NetTCPConnection -LocalPort 80).OwningProcess 

You will see the process name in the results.

How to Check Process Name by Port in PowerShell
Checking the process name running on specific port

Conclusion

In this tutorial, you have learned two methods to find process name listening on a specific port on a Windows system.

The post Which Process is Listening on a Port in Windows appeared first on TecAdmin.

]]>
https://tecadmin.net/which-process-is-listening-on-a-port-in-windows/feed/ 1
How to Start and Stop All Sites in IIS https://tecadmin.net/start-stop-all-sites-in-iis/ https://tecadmin.net/start-stop-all-sites-in-iis/#respond Fri, 06 Mar 2020 13:43:41 +0000 https://tecadmin.net/?p=20751 Internet Information Service (IIS) is the popular web server developed by Microsoft Corporation. It runs on Windows servers and serve websites to users. The PowerShell is the configuration and management application for the Microsoft systems. In this tutorial you will learn how to enable (start) or disable (stop) all sites in single command with PowerShell. [...]

The post How to Start and Stop All Sites in IIS appeared first on TecAdmin.

]]>
Internet Information Service (IIS) is the popular web server developed by Microsoft Corporation. It runs on Windows servers and serve websites to users. The PowerShell is the configuration and management application for the Microsoft systems. In this tutorial you will learn how to enable (start) or disable (stop) all sites in single command with PowerShell.

Useful links:

Launch PowerShell

Type PowerShell in application search option. Then right click on PowerShell application and select “Run as administrator”. This will provide you administrative privileges to perform actions.

Launch powershell as administrator

Start or Stop All Sites in IIS

The WebAdministration module provides the methods to manage IIS on windows system. So first, import WebAdministration module on Powershell, then run the following commands to start or stop all IIS sites.

Stop all sites

Import-Module WebAdministration
Get-ChildItem -Path IIS:\Sites | foreach { Stop-WebSite $_.Name; }

Start all sites

Import-Module WebAdministration
Get-ChildItem -Path IIS:\Sites | foreach { Start-WebSite $_.Name; }

The post How to Start and Stop All Sites in IIS appeared first on TecAdmin.

]]>
https://tecadmin.net/start-stop-all-sites-in-iis/feed/ 0
How To Send Email From Windows Command Line https://tecadmin.net/send-email-from-windows-command-line/ https://tecadmin.net/send-email-from-windows-command-line/#comments Sat, 16 Mar 2019 03:20:48 +0000 https://tecadmin.net/?p=18096 This tutorial will help you to send an email from the Windows command line via remote SMTP server. You need SMTP server details for sending email from Windows PowerShell command. Send Email from Windows PowerShell Once you have SMTP details, open Windows PowerShell and execute the following commands one by one. You need to change [...]

The post How To Send Email From Windows Command Line appeared first on TecAdmin.

]]>
This tutorial will help you to send an email from the Windows command line via remote SMTP server. You need SMTP server details for sending email from Windows PowerShell command.

Send Email from Windows PowerShell

Once you have SMTP details, open Windows PowerShell and execute the following commands one by one. You need to change the orange highlighted values with the appropriate values as per your setup.

$EmailFrom = “from-email@example.com”
$EmailTo = “to-email@example.org”
$Subject = “Email Subject Here”
$Body = “This is mail body”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“SMTP Username”, “SMTP Password”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

This will send email to the recipient address via defined remote SMTP server. You can also write this in a PowerShell script and execute.

The post How To Send Email From Windows Command Line appeared first on TecAdmin.

]]>
https://tecadmin.net/send-email-from-windows-command-line/feed/ 7
PowerShell – Running scripts is disabled on this system https://tecadmin.net/powershell-running-scripts-is-disabled-system/ https://tecadmin.net/powershell-running-scripts-is-disabled-system/#comments Wed, 01 Mar 2017 09:31:40 +0000 https://tecadmin.net/?p=11909 Problem: This error comes when the PowerShell execution policy doesn’t allow us to run scripts. I also found the same error when tried to run a PowerShell script. Solution: The PowerShell execution policy is default set to Restricted. You can change the PowerShell execution policies with Set-ExecutionPolicy cmdlet. To run outside script set policy to [...]

The post PowerShell – Running scripts is disabled on this system appeared first on TecAdmin.

]]>
Problem:

This error comes when the PowerShell execution policy doesn’t allow us to run scripts. I also found the same error when tried to run a PowerShell script.

PowerShell running scripts is disabled on this system

Solution:

The PowerShell execution policy is default set to Restricted. You can change the PowerShell execution policies with Set-ExecutionPolicy cmdlet. To run outside script set policy to RemoteSigned.

PS C:\> Set-ExecutionPolicy RemoteSigned 

Below is the list of four different execution policies in PowerShell

  • Restricted – No scripts can be run.
  • AllSigned – Only scripts signed by a trusted publisher can be run.
  • RemoteSigned – Downloaded scripts must be signed by a trusted publisher.
  • Unrestricted – All Windows PowerShell scripts can be run.

You Should Also Know:

Run the following command to get current execution policy in set in PowerShell.

PS C:\> get-executionpolicy 

You can bypass this policy by adding -ExecutionPolicy ByPass when running PowerShell script.

c:\> powershell -ExecutionPolicy ByPass -File script.ps1

Reference: https://technet.microsoft.com/en-us/library/ee176961.aspx

The post PowerShell – Running scripts is disabled on this system appeared first on TecAdmin.

]]>
https://tecadmin.net/powershell-running-scripts-is-disabled-system/feed/ 17