20 Windows PowerShell commands you need to know (2023)

Windows PowerShell es nuevocommand line shell, which ismore powerful and programmableas notice. In my three years of experience, I have found it very useful, especially if you likeAutomate or create task scripts🇧🇷 However, most of us don't know about it or prefer to use it instead of the old command line shell.

In this post I will shareuseful but simple commands(with examples) of Windows PowerShell. You can use these commands to achieve thisnumerous tasks— from getting help to filing lawsuits. Shall we start?

Observation:Windows PowerShell is built withbackwards compatibilityin mind and is therefore compatible with many command prompt commands. However, you can still use the old commands in the new colorful interface.

Also read: Tips and tools to automate repetitive tasks in Windows 10

Get help [help]

If you're new to PowerShell, you might run into trouble; and in those situations, Get-Help becomes your savior. offersnecessary information about cmdlets, commands, functions, scripts, and PowerShell workflows.

Besides, it's easy: you have to writeget helpfollowed by the command whose details you are looking for. For example, you can get information about "Get-Process" withGet help Get process.

20 Windows PowerShell commands you need to know (1)

get command [gcm]

Windows PowerShell allows you to discover its commands and functions with Get-Command. show the list ofCommands of a specific functionor for a specific purpose based on your search parameter.

All you have to do is writeget commandfollowed by your search query in PowerShell. For example,Get-Command *-Service*displays commands with "-service" in their name. Please keep this in mind.Use asterisks on both sides of your querybecause he is a joker who helps in the search for the unknown.

(Video) 15 Useful PowerShell Commands for Beginners | Learn Microsoft PowerShell

20 Windows PowerShell commands you need to know (2)

call command [icm]

If you wantRun a command or scriptfrom PowerShell, local or remote on one or more computers, "Invoke-Command" is your friend. It is easy to use and will help you control computers in batches.

you must entercall commandfollowed by the command or script with its full path. For example, you canRun a Get-EventLog commandto useInvoke-Command -ScriptBlock {Get-EventLog-System -Newest 50}or use Server01 on a remote computerInvoke-Command -ScriptBlock {sistema Get-EventLog -Newest 50} -ComputerName Server01.

20 Windows PowerShell commands you need to know (3)

invocation expression [iex]

invocation expressionrun another command or expression🇧🇷 If you provide an expression or string as input, this command first evaluates it and then executes it, but unlike the previous command, it also only works locally.

you must enterinvocation expressionfollowed by a command or an expression. For example, you can assign a $Command variable to a string that specifies the Get-Process command. when you run$command call expression, Get-Process is executed as a command on your local computer.

20 Windows PowerShell commands you need to know (4)

Invoke-WebRequest [iwr]

You candownload, sign in and find informationon websites and web services while working in Windows PowerShell with Invoke-WebRequest.

you have to use likeInvoke-WebRequestfollowed by its parameters. For example, you can get the links to a specific web page using the as command.(Invoke-WebRequest-Uri „https://docs.microsoft.com“).Links.Href.

20 Windows PowerShell commands you need to know (5)

Establecer-ExecutionPolicy

You can create and run scripts (with the "ps1" extension) in Windows PowerShell; However, there are limitations for security reasons. if you canchange security levelwith the Set-ExecutionPolicy command.

You can writeEstablecer-ExecutionPolicyfollowed by one of four security levels:Restricted, Remote Signed, All Signed, or No Restrictionsto use the command. For example, you can assign a restricted policy status withSet-ExecutionPolicy -ExecutionPolicy Restrito.

20 Windows PowerShell commands you need to know (6)

Get item [gi]

if you are lookinginformation about an itemAnywhere, like a file on your hard drive, Get-Item is the best way to get it in Windows PowerShell. you have to knowElement content is not retrieved, such as files and subdirectories in a given directory, unless you specifically specify it.

(Video) 40 Windows Commands you NEED to know (in 10 Minutes)

you must enterGets the objectfollowed by a path or string along with its parameters, if any. For example, you can get all items (files or folders) in the current directory that start with "M" usingGet item M*🇧🇷 In addition to the content of directories, you can also retrieve the content of registry keys.

20 Windows PowerShell commands you need to know (7)

copy element [copy]

if you have toCopy files and directorieson your memory disk or registry entries and keys in the registry, you can use Copy-Item. It works similar to the "cp" command we have at the command prompt, but much better.

you can make use of itcopy itemcommand toCopy and rename elements in the same commandalso: enter a new name as destination. For example, you can copy Services.htm and rename it MyServices.txtCopiar elemento "C:\Services.htm" -Destino "C:\MyData\MyServices.txt".

remove article [from]

If you wishdelete itemsuch as files, folders, functions, and registry keys and variables, Remove-Item is the right command for you. What I found interesting is that it provides parameters to include and exclude elements.

you can make use of itremover elementcommand toExclude items from specific locations using parameters🇧🇷 For example, you can use the command to delete the MyServices.txt fileEliminar elemento "C:\MyData\MyServices.txt".

get content [cat]

If you need to see the contents of a text file in a specific location, open it and read it in acovon/axt editor like Notepad++🇧🇷 In Windows PowerShell you can use Get-Content to do thisget the contentwithout opening the file.

For example, you can get 50 lines of content from Services.htm that you can useGet Content "C:\Services.htm" -TotalCount 50.

Set content [sc]

You can save text to files with Set-Content, similar to the "echo" command inBash-Shell🇧🇷 This is also possible in combination with Get-ContentGet the content of a file and copy it to another filewith this command.

For example, you can writedefine contentbywrite or replace contenta file with new content. Also, you can connect it to the command example above to save its output to a new file called "Sample.txt".Get Content "C:\Services.htm" -TotalCount 50 | Set content "Sample.txt".

(Video) Top 5 Useful PowerShell Commands

20 Windows PowerShell commands you need to know (8)

get variable [gv]

If you want to use variables in Windows PowerShell, the Get-Variable command will help you.View variable values🇧🇷 It shows them in a tabular form and allows you to include, exclude and use wildcards.

You can use this command by typingget variablefollowed by its options and parameters. For example, you can get the value of a variable named "desc" with the following code:Get-Variable -Name "desc".

Set-Variable [set]

You canassign or change/reset the value of a variablewith the command set variables. As a shortcut, you can also define a simple variable of the form ${$VarName = VarWert}$, like$desc = "A description".

You can use the commandvariable-setfollowed by its parameters to define a variable. For example, we can set the value of a variable named "desc" using the commandSet-Variable -Name "desc" -Value "A Description".

20 Windows PowerShell commands you need to know (9)

get process [gps]

We usually use the task managerFind running processeson our computer. In Windows PowerShell, anyone can use Get-Process to get the list of currently running processes, which they can also manipulate.

You can write the command asget processalong with your search query. For example, if you need information about processes with "Explore" in the name, you can enter themGet-Process *explorar*(Note the asterisks).

Start process [you know]

O Windows PowerShell facilitaStart one or more processeson your computer I found this command useful when programming applications, as it is one of the required commands needed to automate a task.

You can writestartup processfollowed by its parameters to use the command. For example, you can start Notepad by typingStartup process -FilePath "notepad" -Verb runAssin Windows PowerShell.

20 Windows PowerShell commands you need to know (10)

stop the process [kill]

You canStop specific or all instances of a running processon your computer by name or PID (process ID) thanks to the Stop-Process command. What makes it attractive is that you can see if a process has been stopped or not, and you can even stop processes that don't belong to or have not been started by the current user.

(Video) The Only Three PowerShell Commands You'll Ever Need

You can write the commandstop the processfollowed by its parameters to stop the specified processes. For example, you can use the command to stop all Notepad processesStop-Process -Name "notepad".

Get Service [gsv]

If you needInformation about specific services.(running or stopped) on your computer, you can use Get-Service. It displays the services installed on your system and provides filtering and include/exclude options.

If you want to use this command, you can type itget servicefollowed by its parameters. For example, type the followingGet service | Where-Object {$_.Status -eq "Running"}to get the services "up and running" on your system.

20 Windows PowerShell commands you need to know (11)

Start service [sasv]

If you wishstart a serviceOn your computer, the Start-Service command can help you do the same through Windows PowerShell. I found it powerful enough to start a service even if that service is disabled on your computer.

You must provide the name of the service when using the commandstart the service🇧🇷 For example,Startup service name "WSearch"start the "Windows Search" service on your local computer.

stop service [spsv]

If you wishstop running serviceson your computer, the Stop-Service command will come in handy. You must include the name of the service withservice stop🇧🇷 For example, writeStop-Service-Name "WSearch"to stop the Windows Search service on your computer.

20 Windows PowerShell commands you need to know (12)

Convert to HTML

PowerShell can provide incredible information about your system. However, it is usually presented in a non-digestible format, but you can use ConvertTo-HTML to do this.Create and format a reportto review it or send it to someone else.

you can useConvert to HTMLalong with the output of another command using pipes. For exampleGet service | ConvertTo-HTML -Eigenschaftsname, Status > C:\Services.htmdisplays the list of all services and their status in the form of a web report stored in the Services.htm file.

20 Windows PowerShell commands you need to know (13)

Videos

1. 15 CMD Commands Every Windows User Should Know
(MakeUseOf)
2. Learn and use PowerShell with just three commands
(TechThoughts)
3. Learn and use PowerShell with just three commands - OLD
(TechThoughts)
4. Top 10 useful PowerShell commands
(Daniel Gauthier - TwinBytes Inc)
5. 9 Command Prompt Commands You Should Know!
(ThioJoe)
6. How to find Commands in Windows PowerShell
(Intellezy Learning)
Top Articles
Latest Posts
Article information

Author: Allyn Kozey

Last Updated: 01/11/2023

Views: 6507

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.