Cmdlets provide the basic foundation for working with a computer
from within the Windows PowerShell. Although there are many different
cmdlets with many different available uses, cmdlets all have common
features, which I’ll examine in this section.
Using Windows PowerShell cmdlets
At the Windows PowerShell prompt, you can get a complete list of cmdlets available by typing get-command.
However, the output lists both cmdlets and functions by name and
definition. For cmdlets, the definition provided is the syntax, but the
full syntax rarely fits on the line. A better way to get information
about cmdlets is to use Get-Help.
If you type get-help *-*,
you get a list of all cmdlets, including a synopsis that summarizes the
purpose of the cmdlet—which is much more useful than a list of
commands. To get help documentation on a specific cmdlet, type get-help followed by the cmdlet name, such as:
get-help get-variable
Windows PowerShell uses online and updatable help files. Because of
this, you may see only basic syntax for cmdlets and functions. To get
full help details, you’ll have to either use online help or download
the help files to your computer. For online help, add the -online
option to your get-help command, such as:
get-help get-variable -online
Use the Update-Help cmdlet to download and install the current help
files from the Internet. Without parameters, Update-Help updates the
help files for all modules installed on the computer. However,
Update-Help:
-
Downloads files only once a day -
Installs files only when they are newer than the ones on the computer -
Limits the total size of uncompressed help files to 1 GB
You can override these restrictions using the -Force parameter. Table 1
provides a list of cmdlets you’ll commonly use for administration.
Although many other cmdlets are available, these are the ones you’re
likely to use the most. Table 1. Cmdlets commonly used for administration
CMDLET NAME
|
DESCRIPTION
|
Add-Computer, Remove-Computer, Stop-Computer, Restart-Computer |
Adds or removes domain membership or stops or restarts a computer |
Add-JobTrigger, Get-JobTrigger, New-JobTrigger, Set-JobTrigger |
Cmdlets for adding, getting, creating, and setting triggers for scheduled jobs. |
Checkpoint-Computer, Restore-Computer |
Creates a system restore checkpoint for a computer, or restores a computer from a checkpoint |
Compare-Object, Group-Object, Sort-Object, Select-Object, New-Object |
Cmdlets for comparing, grouping, sorting, selecting, and creating objects |
Connect-PSSession, Disconnect-PSSession |
Connects or disconnects of PowerShell remote session. |
ConvertFrom-SecureString, ConvertTo-SecureString |
Cmdlets for creating or exporting secure strings |
Get-Alias, New-Alias, Set-Alias, Export-Alias, Import-Alias |
Cmdlets for getting, creating, setting, exporting, and importing aliases |
Get-AuthenticodeSignature, Set-AuthenticodeSignature |
Cmdlets for getting or setting the signature object associated with a file |
Get-Command, Invoke-Command, Measure-Command, Trace-Command |
Cmdlets for getting information about cmdlets, invoking commands, measuring the run time of commands, and tracing commands |
Get-Counter |
Gets performance counter data |
Get-Credential |
Gets a credential object based on a password |
Get-Date, Set-Date |
Gets or sets the current date and time |
Get-EventLog, Write-EventLog, Clear-EventLog |
Gets events, writes events, or clears events in an event log |
Get-ExecutionPolicy, Set-ExecutionPolicy |
Gets or sets the effective execution policy for the current shell |
Get-Host |
Gets information about the PowerShell host application |
Get-HotFix |
Gets the Quick Fix Engineering (QFE) updates that have been applied to a computer |
Get-Location, Set-Location |
Displays or sets the current working location |
Get-Process, Start-Process, Stop-Process |
Gets, starts, or stops processes on a computer |
Get-PSDrive, New-PSDrive, Remove-PSDrive |
Gets, creates, or removes a specified PowerShell drive |
Get-ScheduledJob, Disable-ScheduledJob, Enable-ScheduledJob, Set-ScheduledJob |
Cmdlets for getting, disabling, enabling, and setting scheduled jobs |
Get-Service, New-Service, Set-Service |
Gets, creates, or sets system services |
Get-Variable, New-Variable, Set-Variable, Remove-Variable, Clear-Variable |
Cmdlets for getting, creating, setting, and removing variables as well as for clearing variable values |
Import-Counter, Export-Counter |
Imports or exports performance counter log files |
New-EventLog, Remove-EventLog, Limit-EventLog |
Creates or removes a custom event log and event source, or sets the size and age limits for an event log |
Read-Host, Write-Host, Clear-Host |
Reads input from, writes output to, or clears the host window |
Reset-ComputerMachinePassword |
Changes and resets the machine account password that the computer uses to authenticate in a domain |
Show-EventLog |
Displays a computer’s event logs in Event Viewer |
Start-Sleep |
Suspends shell or script activity for the specified period |
Stop-Service, Start-Service, Suspend-Service, Resume-Service, Restart-Service |
Cmdlets for stopping, starting, suspending, resuming, and restarting system services |
Wait-Process |
Waits for a process to be stopped before accepting input |
Write-Output |
Writes an object to the pipeline |
Write-Warning |
Displays a warning message |
All
cmdlet parameters are designated with an initial dash (-). To reduce
the amount of typing required, some parameters are position-sensitive,
so you can sometimes pass parameters in a specific order without having
to specify the parameter name. For example, with Get-Service, you don’t
have to specify the -Name parameter, you can simply type:
get-service ServiceName
where ServiceName is the name of the service you want to examine, such as:
get-service MSExchangeIS
This command line returns the status of the Microsoft Exchange
Information Store service. Because you can use wildcards, such as *,
with name values, you can also type get-service mse* to return the status of all Microsoft Exchange–related services.
All cmdlets support the common set of parameters listed in Table 2.
However, to use these parameters, you must run the cmdlet in such a way
that these parameters are returned as part of the result set. Table 2. Common cmdlet parameters
PARAMETER NAME
|
DESCRIPTION
|
Confirm |
Pauses processes and requires the user to acknowledge the action before continuing. Cmdlets beginning with Remove and Disable have this parameter. |
Debug |
Provides programming-level debugging information about the operation. |
ErrorAction |
Controls the command behavior when an error occurs. |
ErrorVariable |
Sets the name of the variable (in addition to the standard error) in which to place objects for which an error has occurred. |
OutBuffer |
Sets the output buffer for the cmdlet. |
OutVariable |
Sets the name of the variable in which to place output objects. |
Verbose |
Provides detailed information about the operation. |
WarningAction |
Determines how a cmdlet responds to a warning message. Valid values
are SilentlyContinue (suppress the warning and continue), Continue
(display the warning and continue), Inquire (display the warning and
prompt to confirm before continuing), and Stop (display the warning and
halt execution). The default value is Continue. |
WarningVariable |
Sets the name of the variable (in addition to the standard error) in which to store warnings that have occurred. |
WhatIf |
Allows the user to view what would happen if a cmdlet were run with
a specific set of parameters. Cmdlets beginning with Remove and Disable
have this parameter. |
|