Running Powershell Commands
Click here to load reader
-
Upload
pentatonicman1 -
Category
Documents
-
view
215 -
download
0
Transcript of Running Powershell Commands
![Page 1: Running Powershell Commands](https://reader038.fdocuments.in/reader038/viewer/2022100505/577cc69c1a28aba7119ea68c/html5/thumbnails/1.jpg)
8/12/2019 Running Powershell Commands
http://slidepdf.com/reader/full/running-powershell-commands 1/3
Anatomy of a Command
Cmdlet Naming Convention
Terminology
- A cmdlet
is a native Powershell command-line utility. Exist only in PowerShell and are writtenin .NET Framework languages like C#.- A function is similar to a cmdlet, but is written in PowerShell's scripting language rather than a.NET language.- A workflow is a special kind of function that ties into PowerShell's workflow execution system.
Cmdlet Naming- The naming convention established by microsoft for cmdlets is Verb-Noun.- Approved verbs can be seen in powershell by using the Get-Verb cmdlet.
Aliases: nicknames for commands- An alias is a nickname for a command.- There are two ways to get an alias: 1. Use the Get-Alias command byitself to view all available alias' in the powershell session. 2. Use Get-Alias -Definition %command% to get the alias for a specific command.- If you see an alias in a script and want to know which command it corresponds to, just type inhelp and the alias name. The help file for the appropriate command will show (ie. help gsv =help Get-Service)- Aliases can be created, set, imported, and exported using the %Verb%-Alias commands.
Taking Shortcuts
Truncating parameter names- Parameter names can be truncated for brevity. For example, -ComputerName can be typedin as -Comp .- So long as the parameter is unambiguous, it can be accepted. So, if a cmdlet has a -Common and -Computername parameter, you need to type enough of the parameters forPowerShell to know which command you are referring to.
Positional parameters- You must type all the positional parameters you wish to use BEFORE you insert any namedparameters.- Recommended to not use positional parameters in anything that persists (such as scripts orblog posts) as others may not know what parameter you are specifying.
![Page 2: Running Powershell Commands](https://reader038.fdocuments.in/reader038/viewer/2022100505/577cc69c1a28aba7119ea68c/html5/thumbnails/2.jpg)
8/12/2019 Running Powershell Commands
http://slidepdf.com/reader/full/running-powershell-commands 2/3
Show-Command- Cmdlet that provides a GUI for you to insert the parameters for the specified command. Is agood option for learning the proper use of a command if you are not sure about parameternames/values.
- So, for the Get-EventLog cmdlet, you would use Show-Command Get-EventLog to get aGUI which you can use to insert parameter values.- After inserting the desired parameters, use the Run option to immediately run the command.
Alternatively, you can Copy the command to the clipboard and paste it into notepad orpowershell, for instance.
External Commands- Normal windows commands (such as ping) will work with powershell. They work bypowershell using a parser to determine what you want to run, and then opening cmd.exe in thebackground to execute the command.- Sometimes the parser doesn't guess correctly. For this, the command may not work without
some tweaking.- For example, if a command has a lot of parameters, you may need to specify the parametersas variables:
- Alternatively, you can add --% in front of any external command. This bypasses the parserand pass it to cmd.exe.
- More info on parsing can be found by reading the about_parsing help topic.
Dealing with Errors- Errors will normally show the line on which the command (or script) failed.- Sometimes it pays to check the help for a command to see if you have incorrectly specified aparameter, or made any other error with the cmdlet.
![Page 3: Running Powershell Commands](https://reader038.fdocuments.in/reader038/viewer/2022100505/577cc69c1a28aba7119ea68c/html5/thumbnails/3.jpg)
8/12/2019 Running Powershell Commands
http://slidepdf.com/reader/full/running-powershell-commands 3/3