{"id":40382,"date":"2020-04-23T15:30:46","date_gmt":"2020-04-23T11:30:46","guid":{"rendered":"https:\/\/www.msp360.com\/resources\/?p=40382"},"modified":"2025-01-24T17:43:05","modified_gmt":"2025-01-24T13:43:05","slug":"top-10-powershell-commands","status":"publish","type":"post","link":"https:\/\/www.msp360.com\/resources\/blog\/top-10-powershell-commands\/","title":{"rendered":"Top 10 PowerShell Commands Every IT Admin Should Know"},"content":{"rendered":"<p>PowerShell needs no introduction \u2014 it\u2019s the configuration management and task automation framework of choice for the Windows environment. It combines the flexibility of a powerful scripting language with the power and speed of the command line to help IT admins orchestrate, automate and troubleshoot common IT functions.<!--more--><\/p>\n<p>As such, PowerShell is an indispensable tool for MSPs looking for a way to easily manage computers and servers across clients\u2019 IT environments. More importantly, PowerShell remoting enables IT admins to access PowerShell sessions and run PowerShell commands on remote Windows systems.<\/p>\n<p>PowerShell\u2019s ability to execute remote management commands is especially beneficial to sysadmins, who can use it to manage multiple IT environments. This increases productivity and helps to overcome several challenges common to the MSP workspace. To help you get started, let\u2019s take a look at some of the basic PowerShell commandlets that your IT admins should know.<\/p>\n<div class=\"call-to-action\">\n<div class=\"call-to-action__left\" style=\"width: 70%;\">\n<div class=\"call-to-action__title\">How to Remotely Manage Your Servers Using PSRemoting and Invoke PowerShell Commands<\/div>\n<div class=\"call-to-action__text\">\n<ul>\n<li>Making a new firewall rule<\/li>\n<li>Restarting the server or computer<\/li>\n<li>Restating certain services<\/li>\n<li>Checking the status of the service, and more<\/li>\n<\/ul>\n<\/div>\n<!--HubSpot Call-to-Action Code --><span class=\"hs-cta-wrapper hs-cta-deferred\" id=\"hs-cta-wrapper-cb170909-0383-4fad-a48e-d167b3c0bc63\" data-portal=\"5442029\" data-id=\"cb170909-0383-4fad-a48e-d167b3c0bc63\"><span class=\"hs-cta-node hs-cta-cb170909-0383-4fad-a48e-d167b3c0bc63\" id=\"hs-cta-cb170909-0383-4fad-a48e-d167b3c0bc63\"><!--[if lte IE 8]><div id=\"hs-cta-ie-element\"><\/div><![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/5442029\/cb170909-0383-4fad-a48e-d167b3c0bc63\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"hs-cta-img\" id=\"hs-cta-img-cb170909-0383-4fad-a48e-d167b3c0bc63\" style=\"border-width:0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/5442029\/cb170909-0383-4fad-a48e-d167b3c0bc63.png\" alt=\"CTA\"><\/a><\/span><\/span><!-- end HubSpot Call-to-Action Code -->\n<\/div>\n<div class=\"call-to-action__right\" style=\"width: 30%;\"><img decoding=\"async\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2020\/04\/PowerShell-script-for-managing-servers-remotely.png\" alt=\"WP icon\" \/><\/div>\n<\/div>\n<h2>1. Get-Help<\/h2>\n<p>Get-Help is a simple but very useful command that enables admins to obtain helpful information about other PowerShell cmdlets, scripts, etc. If you need to know how the Get-EventLog command works, all you need to do is type \u201cGet-Help -Name Get-EventLog\u201d and Windows displays the full command syntax.<\/p>\n<h2>2. Get-Command<\/h2>\n<p>This displays the list of commands that correspond to the search parameter you entered. Admins can use this command by typing Get-Command followed by their search query. For instance, \u201cGet-Command *-service*\u201d displays all the commands associated with -service.<\/p>\n<h2>3. Get-Service<\/h2>\n<p>This command provides you with the list of services installed on your system. If you include the -Name switch as well as the name of the service as parameters to the Get-Service command, Windows will display the state of the service.<\/p>\n<h2>4. Get-Process<\/h2>\n<p>This command is similar to the Get-Service command. It\u2019s used to get the list of all running processes on your computer.<\/p>\n<h2>5. Set-ExecutionPolicy<\/h2>\n<p>In line with security best practices, Windows has four built-in levels of access to the PowerShell environment. They are Restricted, All Signed, Remote Signed and Unrestricted.<\/p>\n<ul>\n<li><strong>Restricted<\/strong> \u2014 this locks down PowerShell and ensures that the environment is unable to run PowerShell scripts. You can only enter this command interactively.<\/li>\n<li><strong>Unrestricted<\/strong> \u2014 this removes all execution policy restrictions.<\/li>\n<li><strong>All Signed<\/strong> \u2014 in this mode, only scripts signed by trusted publishers are allowed to run.<\/li>\n<li><strong>Remote Signed<\/strong> \u2014 setting the execution policy to Remote Signed allows the execution of all scripts created locally. Scripts created remotely are allowed to run only if they are signed by trusted publishers.<\/li>\n<\/ul>\n<p>To prevent the execution of malicious code in the PowerShell environment, scripting is disabled by default \u2014 i.e. set to Restricted. The Set-ExecutionPolicy command allows you to select your preferred level of security. All you need to do is enter the Set-ExecutionPolicy command and the policy name. For instance, \u201cSet-ExecutionPolicy Unrestricted\u201d.<\/p>\n<div class=\"call-to-action\">\n<div class=\"call-to-action__left\" style=\"width: 75%;\">\n<div class=\"call-to-action__title\">PowerShell Remote Alerts<\/div>\n<div class=\"call-to-action__text\">\n<p>In this document you'll find a PowerShell script that checks the status of the services listed below and sends an email alert if any of them is turned off:<\/p>\n<ul>\n<li>Windows Firewall<\/li>\n<li>Windows Defender<\/li>\n<li>Windows Update Service<\/li>\n<li>Any installed third-party antivirus<\/li>\n<\/ul>\n<\/div>\n<!--HubSpot Call-to-Action Code --><span class=\"hs-cta-wrapper hs-cta-deferred\" id=\"hs-cta-wrapper-1555841d-7c2e-4434-84c6-e67830d5e7c1\" data-portal=\"5442029\" data-id=\"1555841d-7c2e-4434-84c6-e67830d5e7c1\"><span class=\"hs-cta-node hs-cta-1555841d-7c2e-4434-84c6-e67830d5e7c1\" id=\"hs-cta-1555841d-7c2e-4434-84c6-e67830d5e7c1\"><!--[if lte IE 8]><div id=\"hs-cta-ie-element\"><\/div><![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/5442029\/1555841d-7c2e-4434-84c6-e67830d5e7c1\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"hs-cta-img\" id=\"hs-cta-img-1555841d-7c2e-4434-84c6-e67830d5e7c1\" style=\"border-width:0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/5442029\/1555841d-7c2e-4434-84c6-e67830d5e7c1.png\" alt=\"CTA\"><\/a><\/span><\/span><!-- end HubSpot Call-to-Action Code -->\n<\/div>\n<div class=\"call-to-action__right\" style=\"width: 25%;\"><img decoding=\"async\" src=\"https:\/\/www.msp360.com\/resources\/wp-content\/uploads\/2019\/12\/Powershell-alerts-icon.png\" alt=\"WP icon\" \/><\/div>\n<\/div>\n<h2>6. Get-ExecutionPolicy<\/h2>\n<p>As an IT admin working on unfamiliar computers and servers, you should first find out the status of the execution policy before running a script. The Get-ExecutionPolicy command helps you do this.<\/p>\n<h2>7. Start-Service<\/h2>\n<p>The Start-Service command allows you to start any service on Windows \u2014 even if the service is disabled. To do this, append the name of the service to the Start-Service command. For example, \u2018Start-Service -Name \"WSearch\"\u2019 opens up Windows Search.<\/p>\n<h2>8. Start-Process<\/h2>\n<p>This is quite similar to the Start-Service command and allows you to start one or more processes via PowerShell. Use the Start-Process command followed by the requisite parameters to start a process.<\/p>\n<h2>9. Stop-Process<\/h2>\n<p>The Stop-Process command enables you to stop a process (or some of its instances) currently running on a computer. This is particularly useful when a process freezes up. Use the Get-Process command to get the process ID or name of the unresponsive process.<\/p>\n<p>Terminate the process by typing the Stop-Process command with the process ID or process name. For instance, you can stop all Notepad processes using the following command:<\/p>\n<pre><code>Stop-Process -Name notepad<\/code><\/pre>\n<p>You can also stop a particular instance of a process using its process ID:<\/p>\n<pre><code>Stop-Process -ID 1943<\/code><\/pre>\n<h2>10. ConvertTo-HTML<\/h2>\n<p>The ConvertTo-HTML command is a useful tool that admins can use to transfer the output of a PowerShell command\/script into a report for further analysis or to send to someone else. For example, you may want to create a report that lists all the running processes on a local computer, as well as their current status. To do this, you can use this command:<\/p>\n<pre><code>Get-Process | ConvertTo-HTML -Property Name, Status &gt; C:\\processes.htm<\/code><\/pre>\n<p>This command will store the list of all running processes (in the form of a Web report) in a file called processes.htm<\/p>\n<h2>Advanced Scripts<\/h2>\n<p>Here are links to more-complex PowerShell scripts for advanced users. These scripts are particularly useful for automating IT admin tasks and solving challenges common to MSP operations.<\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/proxb\/PowerShell_Scripts\/blob\/master\/Set-Password.ps1\" target=\"_blank\" rel=\"noopener noreferrer\">Set user password on the local or remote machine<\/a>. This script allows admins to set passwords for user accounts on remote and local machines.<\/li>\n<li><a href=\"https:\/\/gallery.technet.microsoft.com\/scriptcenter\/Check-for-hung-or-stopped-67bc718d\" target=\"_blank\" rel=\"noopener noreferrer\">Check for stopped or hung services<\/a>. This script allows you to check if services (on remote systems you specify) are hung or stopped. If there are any such services, you\u2019ll receive a notification email. The script then stops hung services and attempts to restart them.<\/li>\n<li><a href=\"https:\/\/gallery.technet.microsoft.com\/Reset-password-for-all-412fbc72\" target=\"_blank\" rel=\"noopener noreferrer\">Reset password for specified users<\/a>. This script resets passwords for multiple user accounts. It\u2019s particularly useful when your IT admins need to reset the passwords for all users in client organizations.<\/li>\n<li><a href=\"https:\/\/gallery.technet.microsoft.com\/Get-Network-Information-of-6d07766f\" target=\"_blank\" rel=\"noopener noreferrer\">Get network information of remote and local PC\/servers<\/a>. This script returns the network information (IP address, subnet, gateways, and DNS servers) of local and remote machines.<\/li>\n<\/ol>\n<h2>Wrapping Up<\/h2>\n<p id=\"last\">IT admins looking to use PowerShell to manage remote client workstations must first enable PowerShell remoting on the system they want to connect to remotely. This feature is locked down by default and enabling it gives you access to several remote management functions supported by the Windows Remote Management (WinRM) service and the WS-Management protocol.<\/p>\n<div id=\"slidebox\"><a class=\"close\">\u00a0<\/a><!--HubSpot Call-to-Action Code --><span class=\"hs-cta-wrapper hs-cta-deferred\" id=\"hs-cta-wrapper-763c150f-30b3-4ee2-a2a4-a13a79459ca1\" data-portal=\"5442029\" data-id=\"763c150f-30b3-4ee2-a2a4-a13a79459ca1\"><span class=\"hs-cta-node hs-cta-763c150f-30b3-4ee2-a2a4-a13a79459ca1\" id=\"hs-cta-763c150f-30b3-4ee2-a2a4-a13a79459ca1\"><!--[if lte IE 8]><div id=\"hs-cta-ie-element\"><\/div><![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/5442029\/763c150f-30b3-4ee2-a2a4-a13a79459ca1\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"hs-cta-img\" id=\"hs-cta-img-763c150f-30b3-4ee2-a2a4-a13a79459ca1\" style=\"border-width:0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/5442029\/763c150f-30b3-4ee2-a2a4-a13a79459ca1.png\" alt=\"CTA\"><\/a><\/span><\/span><!-- end HubSpot Call-to-Action Code --><\/div>\n<p>Ensure that your technicians configure all client workstations and servers to accept remote PowerShell connections from authorized personnel. <strong>The configuration procedure should be documented in your <a href=\"https:\/\/www.msp360.com\/resources\/blog\/how-to-properly-add-a-new-machine-to-your-managed-services\/\">New PC Checklist<\/a>, standard operating procedures (SOPs), and other <a href=\"https:\/\/www.msp360.com\/resources\/blog\/guide-to-creating-msp-documentation\/\">MSP documentation<\/a>.<\/strong><\/p>\n<p><span class=\"further-reading \">Further reading<\/span> <a href=\"https:\/\/www.msp360.com\/resources\/blog\/document-management-software-for-msps\/\">Best Document Management Software Options for MSPs<\/a><\/p>\n<p>While PowerShell isn\u2019t a silver bullet for all your IT admin workloads, it comes pretty close. In the hands of a proficient IT professional, it can help streamline and resolve several hurdles in the MSP workspace, resulting in increased productivity, better service delivery, and more satisfied clients.<\/p>\n<p>Looking for ready-made solutions? Check out <a href=\"https:\/\/www.msp360.com\/script-library\/\">the MSP360 Script Library<\/a>, featuring free, pre-built PowerShell scripts to streamline your IT tasks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell needs no introduction \u2014 it\u2019s the configuration management and task automation framework of choice for the Windows environment. It combines the flexibility of a powerful scripting language with the power and speed of the command line to help IT admins orchestrate, automate and troubleshoot common IT functions.<\/p>\n","protected":false},"author":81,"featured_media":40383,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[877,884,885],"tags":[],"class_list":["post-40382","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-articles","category-msp-business-articles","category-other"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/40382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/comments?post=40382"}],"version-history":[{"count":3,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/40382\/revisions"}],"predecessor-version":[{"id":59437,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/posts\/40382\/revisions\/59437"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/media\/40383"}],"wp:attachment":[{"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/media?parent=40382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/categories?post=40382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msp360.com\/resources\/wp-json\/wp\/v2\/tags?post=40382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}