IT tutorials
 
Technology
 

Windows Server 2008 : Understanding PowerShell Verbs and Nouns

10/6/2013 7:31:17 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Windows PowerShell commands use basic verbs and nouns. You can usually determine what the command does just by its name. For example, the get-helpget verb with the help noun, and just as you’d expect, it gets help. command combines the

Note

PowerShell commands follow Pascal casing rules, which are also known as camel casing. Pascal casing joins words without spaces but uses uppercase to distinguish them. For example, camel case is written as CamelCase.


Common verbs are as shown in the following table.

Verbs with ExamplesComments
Get
get-command
PS C:\> get-command

Retrieves information. For example, the get-command cmdlet retrieves a listing of all PowerShell commands.
Set
set-executionpolicy policy
PS C:\> set-executionpolicy
remotesigned

Configures a setting. The example sets the PowerShell execution policy to remote signed, allowing local scripts to run.
Format
format-table columns
PS C:\> get-service |
format-table Name, Status,
DependentServices -auto

Formats the output. The example gets a listing of all services but picks specific columns to include in the table.

Tip

The pipe command (|) sends the output from the previous command to the next command. In other words, the output if get-service is sent to format-table.

Tip

The -auto switch helps the output fit on the screen.

Out
Out-file filename
PS C:\> get-process |
out-file processes.txt
PS C:\> get-process >
processes.txt

Sends data out to a file. The example uses get-process to retrieve a listing of all running processes and sends it to a text file named processes.txt. You can achieve the same result using the redirect symbol (>), as shown in the second example.
Gridview
Get-service | out-gridview
PS C:\> get-service |
where-object {$_.status -eq
"running"} | sort-object
-property displayname |
out-gridview

Sends the output to a grid view window similar to Figure 1. The example command uses the where-object cmdlet to list only running services, the sort-object cmdlet to sort on the displayname, and the out-gridview cmdlet to send the output to a gridview window.

Tip

The gridview window allows dynamic sorting by simply clicking on any column to reorder the data.

Note

The gridview requires the Microsoft .NET Framework 3.5 Service Pack 1 (available at http://go.microsoft.com/fwlink?linkid=124150). On Windows Server 2008 R2, it requires that the Windows Integrated Scripting feature be installed via Server Manager.

Selected columns in gridview
Get-process | select
columns | out-gridview
PS C:\> get-process |
select-object name,
description, handles, vm,
ws, pm, npm, cpu,
totalprocessortime |
out-gridview

This example shows how to select specific columns in the gridview by using the select-object cmdlet. The output of this command is shown in Figure 2.

Tip

You can view a list of all selectable columns (and their name in the header) by running get-process | select-object * | out-gridview.

Test
test-path path
PS C:\> test-path c:\data\
processes.txt

Tests various conditions like the existence of a file or the existence of a registry key. The example tests to see whether the path and filename exist. If it exists, it returns a true. If it doesn’t exist, it returns a false.
Write
write-warning message
PS C:\> write-warning
"Success!"

Writes data to various sources such as the screen or event logs. The example writes the message to the screen in yellow text.
Start
start-service servicename
PS C:\> start-service
msftpsvc

You can use this to start jobs, processes, services, and more. The example starts the FTP Publishing Service using the service’s name.

Tip

You can get a list of all services (including their service name) with the get-serviceName column. command. The service name is displayed in the

Stop
stop-service servicename
PS C:\> stop-service
msftpsvc

You can use this to stop jobs, processes, services, and more. The example stops the FTP Publishing Service using the service’s name.
Measure
measure-object
PS C:\> get-command |
measure-object

Provides counts, averages, and other metrics for various objects. The example command counts the number of Windows PowerShell commands and provides the total. There are more than 400 built-in commands.

Figure 1. Windows PowerShell gridview output

Figure 2. Selected columns in Windows PowerShell gridview

Note

This is not a complete list of verbs available in Windows PowerShell. You can get a complete list of all commands by entering get-command at the PowerShell command prompt.


You can also use get-command to retrieve information on commands with specific verbs or with specific nouns.

Get-commandsComments
Getting verbs.
get-command -verb verb
PS C:\> get-command -verb get
PS C:\> get-command -verb out
PS C:\> get-command -verb write

Provides a listing of all commands associated with a specific verb.

The examples show all the commands using the get verb, the out verb, and the write verb. You can also use other verbs, such as set, select, start, and stop.

Tip

You can get a list of all verbs, including the number of commands, using the verb with the following command:

get-command | group-object verb | sort-object count -descending
Getting nouns.
get-command -noun noun
PS C:\> get-command -noun event

Provides a listing of all commands associated with a specific noun.

The example shows all the commands using the noun event. You can also use other nouns such as service, variable, and error.

Tip

You can get a list of all nouns, including the number of commands, using the noun with the following command:

get-command | group-object noun | sort-object count -descending
Looking for strings with wildcards.
get-command * string
PS C:\> get-command *service
PS C:\> get-command *object*

Provides a listing of all commands associated with the string. In the first example, all commands that end in service are shown. The second example shows all commands with the word object anywhere in the command.
 
Others
 
- Windows Server 2008 : Installing and Launching PowerShell
- Sharepoint 2013 : Working with PowerShell (part 3) - PowerShell and SharePoint - Web Applications, Site Collections, Memory and Disposal
- Sharepoint 2013 : Working with PowerShell (part 2) - PowerShell and SharePoint - Administration Permissions, Content Databases
- Sharepoint 2013 : Working with PowerShell (part 1) - PowerShell Basics
- Exchange Server 2010 Quick Start Guide : Installing Exchange Server 2010
- Exchange Server 2010 Quick Start Guide : Configuring Windows Server 2008 R2
- Exchange Server 2010 Quick Start Guide : Server Sizing Quick Reference
- Microsoft Lync Server 2010 : UCMA (part 3) - Walkthrough of the UCMA 3.0 Components - Toolbox Components, Error Condition Components
- Microsoft Lync Server 2010 : UCMA (part 2) - Walkthrough of the UCMA 3.0 Components
- Microsoft Lync Server 2010 : UCMA (part 1) - Server APIs ,Client APIs , PowerShell
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us