-->

10 Powershell Commands Every Windows Admin Should Know - Techrepublic

10 Powershell Commands Every Windows Admin Should Know - Techrepublic

https://www.techrepublic.com/blog/10-things/10-powershell-commands-every-windows-admin-should-know/

Over the terminal few years, Microsoft has been trying to brand PowerShell the administration tool of choice. Almost all the newer Microsoft server products require PowerShell, too in that place are lots of administration tasks that can't survive accomplished without delving into the command line. As a Windows administrator, you lot demand to survive familiar amongst the basics of using PowerShell. Here are 10 commands to acquire you lot started.

Note: This article is also available equally a PDF download.

1: Get-Help

The kickoff PowerShell cmdlet every administrator should larn is Get-Help. You tin shipping away role this command to acquire assist amongst whatsoever other command. For example, if you lot desire to know how the Get-Process command works, you lot tin shipping away type:

Get-Help -Name Get-Process 

and Windows volition display the total command syntax.

You tin shipping away also role Get-Help amongst private nouns too verbs. For example, to uncovering out all the commands you lot tin shipping away role amongst the Get verb, type:

Get-Help -Name Get-* 

2: Set-ExecutionPolicy

ADVERTISING

Although you lot tin shipping away practise too execute PowerShell scripts, Microsoft has disabled scripting past times default inward an motility to foreclose malicious code from executing inward a PowerShell environment. You tin shipping away role the Set-ExecutionPolicy command to command the score of safety surrounding PowerShell scripts. Four levels of safety are available to you:

  • Restricted — Restricted is the default execution policy too locks PowerShell downwards thus that commands tin shipping away survive entered alone interactively. PowerShell scripts are non allowed to run.
  • All Signed — If the execution policy is develop to All Signed too thus scripts volition survive allowed to run, but alone if they are signed past times a trusted publisher.
  • Remote Signed — If the execution policy is develop to Remote Signed, whatsoever PowerShell scripts that convey been locally created volition survive allowed to run. Scripts created remotely are allowed to run alone if they are signed past times a trusted publisher.
  • Unrestricted — As the yell implies, Unrestricted removes all restrictions from the execution policy.

You tin shipping away develop an execution policy past times entering the Set-ExecutionPolicy command followed past times the yell of the policy. For example, if you lot wanted to allow scripts to run inward an unrestricted trend you lot could type:

Set-ExecutionPolicy Unrestricted 

3: Get-ExecutionPolicy

If you're working on an unfamiliar server, you'll demand to know what execution policy is inward role earlier you lot endeavor to run a script. You tin shipping away uncovering out past times using the Get-ExecutionPolicy command.

4: Get-Service

The Get-Service command provides a listing of all of the services that are installed on the system. If you lot are interested inward a specific service you lot tin shipping away append the -Name switch too the yell of the service (wildcards are permitted) When you lot do, Windows volition exhibit you lot the service's state.

5: ConvertTo-HTML

PowerShell tin shipping away render a wealth of information virtually the system, but sometimes you lot demand to practise to a greater extent than than precisely sentiment the information onscreen. Sometimes, it's helpful to practise a written report you lot tin shipping away shipping to someone. One agency of accomplishing this is past times using the ConvertTo-HTML command.

Set your trouble concern apart amongst eye-popping color documents
Research proves that customers prefer color documents over black-and-white. HP's novel copiers deliver affordable color, amongst fewer parts for maximum uptime too unmatched security.
Sponsored by HP

To role this command, precisely pipage the output from or thus other command into the ConvertTo-HTML command. You volition convey to role the -Property switch to command which output properties are included inward the HTML file too you lot volition convey to render a filename.

To encounter how this command mightiness survive used, intend dorsum to the previous section, where nosotros typed Get-Service to practise a listing of every service that's installed on the system. Now imagine that you lot desire to practise an HTML written report that lists the yell of each service along amongst its condition (regardless of whether the service is running). To practise so, you lot could role the next command:

Get-Service | ConvertTo-HTML -Property Name, Status > C:\services.htm 

6: Export-CSV

Just equally you lot tin shipping away practise an HTML written report based on PowerShell data, you lot tin shipping away also export information from PowerShell into a CSV file that you lot tin shipping away opened upwards using Microsoft Excel. The syntax is similar to that of converting a command's output to HTML. At a minimum, you lot must render an output filename. For example, to export the listing of organisation services to a CSV file, you lot could role the next command:

Get-Service | Export-CSV c:\service.csv 

7: Select-Object

If you lot tried using the command above, you lot know that in that place were numerous properties included inward the CSV file. It's oft helpful to narrow things downwards past times including alone the properties you lot are genuinely interested in. This is where the Select-Object command comes into play. The Select-Object command allows you lot to specify specific properties for inclusion. For example, to practise a CSV file containing the yell of each organisation service too its status, you lot could role the next command:

Get-Service | Select-Object Name, Status | Export-CSV c:\service.csv 

8: Get-EventLog

You tin shipping away genuinely role PowerShell to parse your computer's number logs. There are several parameters available, but you lot tin shipping away seek out the command past times precisely providing the -Log switch followed past times the yell of the log file. For example, to encounter the Application log, you lot could role the next command:

Get-EventLog -Log "Application" 

Of course, you lot would rarely role this command inward the existent world. You're to a greater extent than probable to role other commands to filter the output too dump it to a CSV or an HTML file.

9: Get-Process

Just equally you lot tin shipping away role the Get-Service command to display a listing of all of the organisation services, you lot tin shipping away role the Get-Process command to display a listing of all of the processes that are currently running on the system.

10: Stop-Process

Sometimes, a procedure volition freeze up. When this happens, you lot tin shipping away role the Get-Process command to acquire the yell or the procedure ID for the procedure that has stopped responding. You tin shipping away too thus terminate the procedure past times using the Stop-Process command. You tin shipping away terminate a procedure based on its yell or on its procedure ID. For example, you lot could terminate Notepad past times using i of the next commands:

Stop-Process -Name notepad<br> Stop-Process -ID 2668 

Keep inward hear that the procedure ID may alter from session to session.

Additional PowerShell resources


Blogger
Disqus
Pilih Sistem Komentar

No comments

Advertiser