⬆️ ⬇️

Top 7 Powershell Cmdlets for Newbies

Probably everyone has heard of PowerShell, but surely not everyone had a chance to work with it. For those who are just starting to make their way into the jungle of PowerShell, we provide a translation of the post, published on the portal 4sysops.com . It tells about 7 teams that will help those who have just started working with PowerShell. For details - welcome under cat.





GET-HELP

The first and most important PowerShell cmdlet is the help call. Using the Get-Help cmdlet, you can check the syntax, see usage examples and a detailed description of the parameters of any PowerShell cmdlet. This cmdlet is notable for simply typing Get-Help Services to get a list of all cmdlets that are suitable for working with services.

Example:

PS C:\> Get-Help Service 






You can select any cmdlet from the list listed above for the query above. For example,

 PS C:\> Get-Help -Name Get-Service 


You get all the information about the Get-Service cmdlet (discussed below).



')

GET-CONTENT



Reading the contents of files is the most frequent requirement for beginners trying to learn PowerShell. The process of reading files with PowerShell is simplified. Even a layman can read the contents of a file by simply passing it to the Get-Content cmdlet.

Example.

 PS C:\> Get-Content C:\scripts\Computers.txt mytestpc1 techibee.com dummynotresolvinghost.com PS C:\> 






Need more information about the cmdlet? Use Get-Help:

 PS C:\> Get-Help Get-Content -Detailed 




GET-SERVICE



This cmdlet lists all services installed on the computer. You can use it to get information about a particular service, a set of services, or just about all the services on a computer.

Example:

 PS C:\> Get-Service wwansvc, spooler Status Name DisplayName ------ ---- ----------- Running spooler Print Spooler Stopped wwansvc WWAN AutoConfig PS C:\> 




Here we requested information about the two services wwansvc and spooler

A table is displayed with the status of the service, its name and display name.

We can see that the spooler service is running and wwansvc is stopped



STOP-SERVICE AND START-SERVICE



Starting and stopping services is a rather important moment in the work of the Windows administrator. PowerShell has built-in cmdlets that simplify the work of an administrator without requiring you to open the MMC console. Using these cmdlets, you can stop / start services on both local and remote computers.

Examples:

Starting / stopping the service on the local computer (using the example of the spooler service):

 PS C:\> Stop-Service -Name Spooler PS C:\> Start-Service -Name Spooler 




Starting / stopping a service on a remote computer (spooler):

 PS C:\> $ServiceObj = Get-Service -ComputerName MyPC1 -Name spooler PS C:\> Stop-Service -InputObj $ServiceObj PS C:\> Start-Service -InputObj $ServiceObj 




GET-PROCESS



This cmdlet lets you know which processes are running on local or remote computers. Shows the name and ID of the process, as well as the path to the executable file, the company name, the version of the executable file, and the memory used by the process.

Examples:

Getting information about processes running on the local computer:



 PS C:\> Get-Process 






Enter the following cmdlet to get detailed information about running processes.

 PS C:\> Get-Process | Format-List * -Force 




Getting information about processes running on a remote computer :

 PS C:\> Get-Process -ComputerName MYPC1 | Format-List * -Force 




MYPC1 must be replaced with the name of the computer from which you want to receive information about running processes.



STOP-PROCESS



This cmdlet stops the process on a local or remote computer. It takes the name or process ID and terminates the process. This is useful when the application is not responding.

Example:

Stop the process with ID 22608 on the local computer:

 PS C:\> Stop-Process -Id 22608 


Stop all Excel processes on the local computer:

 PS C:\> Stop-Process -name excel 




Tip : Although the Stop-Process cmdlet does not have the -ComputerName parameter, you can still use it to terminate remote processes using the advice below:

 PS C:\> $Obj = Get-Process -Name excel -ComputerName MYPC1 PS C:\> Stop-Process -InputObject $Obj 




Upd:

The post is a translation of an article from the portal 4sysops.com

Top 7 PowerShell commands for beginners



PS See also interesting posts on Habré, dedicated to working with PowerShell

File Access Audit

Audit Active Directory (Part 1 and 2 )

Update Active Directory Credentials

Audit account creation in AD

Source: https://habr.com/ru/post/158943/



All Articles