A cmdlet is a lightweight command that is used in the PowerShell environment. The PowerShell runtime invokes these cmdlets within the context of automation scripts that are provided at the command line. The PowerShell runtime also invokes them programmatically through PowerShell APIs.
Cmdlets are based on .NET classes and rely on the use of .NET objects. Thus, cmdlets can receive objects as input and deliver objects as output, which can then feed the input of subsequent objects, enabling cmdlets to form a command pipeline.
Most cmdlets support the use of parameters as part of the input mechanism. Parameters can be added to the cmdlet at the command line or passed to cmdlets through the pipeline as the output from a previous cmdlet. The arguments or values of each parameter detail the actual input that the cmdlet will accept, how the cmdlet should work and what -- if any -- data the cmdlet outputs. Switches are specialized arguments that offer preset options or selections
How to write simple cmdlets
cmdlets are simple entities and can be easily written in C# or other programming languages that supports .NET object code.
1. Specify the parent class for cmdlets. A cmdlets derives either from System.Management.Automation.cmdlets or System.Management.Automation.PSCmdlet classes. A cmdlets can use the command such as:
using System.Management.Automation;
2. Then Specify the object name. Example, if the new cmdlet is supposed to simply send a test message, C# might use the namespace command such as:
namespace SendTestMessage
3. Declare the class of the object as a cmdlet. The cmdlet attribute enables developers to stipulate the verb and noun elements of the cmdlet name. For example, a C# command that defines a cmdlet and names it "Send-Test" might appear as:
[Cmdlet(VerbsCommunications.Send, "TestMessage")]
4. Specify any parameters for the cmdlet using the parameter attribute. The length and complexity of this code section depends on the number and types of parameters that the cmdlet is intended to handle. For example, if the cmdlet is merely intended to accept the name of a person to receive a test message, a parameter might be to input that individual's name and create the variable string "name". In C#, the code sequence might appear such as:
[Parameter(Mandatory=true)]
public string Name
{
get { return name; }
set { name = value; }
}
private string name;
5. Now the cmdlet has been defined and accepted parameters, the cmdlet code can focus on the actual task at hand. In this case, the task is to take the name parameter and output that name to a simple test message. As an example, the WriteObject command can produce a simple output such as:
{
WriteObject("It is good to meet you " + name + "!");
}
List of PowerShell cmdlets
Command-Name Description
Add-content This cmdlet adds the content to the specified file.
Add-Computer This cmdlet adds the local computer to a domain or workgroup.
Add-History This cmdlet is used to add the command in the history.
Add-jobTrigger This cmdlet adds the job triggers to the scheduled jobs.
Add-member The cmdlet adds the custom methods or properties to an instance of a
PowerShell object
.Add-type This cmdlet adds a Microsoft .NET framework class to a Windows
PowerShell session.
Clear-Content This cmdlet deletes the content of a file, but not delete that file.
Clear-History This cmdlet deletes the entries from the command history.
Clear-Item This cmdlet clears the value of item or variable, but not clear that item or a
variable.
Clear-ItemProperty This cmdlet clears the value of a property but not delete that property.
Clear-Variable This cmdlet deletes the value of a variable.
Clear-Host This cmdlet clears the display of the host program.
Copy-ItemProperty This cmdlet copies a value and property from a specified location to
another location.
Copy-Item This cmdlet copies an item from one location to another.
Complete-Transaction This cmdlet commits the active transaction.
Compare-object This cmdlet compares two sets of objects.
Disable-PSBreakpoint This Cmdlet disables the breakpoint in the current console.
Enable-PSBreakpoint This Cmdlet enables the breakpoint in the current console.
Find-package This cmdlet finds the software packages in the available packages sources.
Find-script This cmdlet is used to find a script
ForEach-Object This cmdlet performs an operation on each item in a collection of input
objects.
Get-Alias This cmdlet gets the aliases for the current session.
Get-childItem This cmdlet gets the item and the child items in one or more specified
locations.
Get-Command This cmdlet is used to get all commands.
Get-Content This cmdlet gets the content of the file at the specified location.
Get-Date This cmdlet is used to get the current date and time.
Get-ExecutionPolicy This cmdlet gets the execution policy for the current session.
Get-Help This cmdlet displays information about PowerShell commands and
concepts.
Get-History This cmdlet displays a list of commands which are entered during the current session.
Get-host This cmdlet gets an object which represents the current host program.
Get-InstalledScript This cmdlet gets a script which is installed for the current user.
Get-Item This cmdlet gets the item or a file at a particular location.
Get-ItemProperty This cmdlet gets the properties of a particular item.
Get-Location This cmdlet displays the current working location.
Get-PSBreakpoint This cmdlet gets the breakpoint which is set in the current session.
Get-Package This cmdlet displays the list of all installed packages by using the package
management.
Get-Process This cmdlet gets the processes which are running on local or remote
computers.
Get-Service This cmdlet gets the services on local or remote computers.
Get-Transaction This cmdlet gets the currently active transaction.
Get-Variable This cmdlet gets the variable in the current console.
Install-package This cmdlet is used to install one or more software packages.
Install-script This cmdlet is used to install a script.
Invoke-commands This cmdlet executes commands on local and remote computers.
Move-Item This cmdlet is used to move an item from one location to another.
Move-ItemProperty This cmdlet is used to move the property of an item from one location to
another.
New-alias This cmdlet creates a new alias.
New-Item This cmdlet creates a new item.
New-ItemProperty This cmdlet creates a new property for an item and sets its value.
New-Service This cmdlet creates a new Window service.
New-variable This cmdlet creates a new variable.
Read-Host This cmdlet reads a line of inputs from the console.
Remove-computer This cmdlet removes a local computer from its domain.
Remove-Item This cmdlet deletes the particular item.
Remove-ItemProperty This cmdlet deletes the property & its value from an item.
Remove-job This cmdlet removes the background job of Windows PowerShell.
Remove-PSBreakpoint This cmdlet deletes the breakpoint from the current console.
Remove-variable This cmdlet deletes a variable with its value.
Rename-computer This cmdlet is used to rename a computer.
Restart-Service This cmdlet stops and starts one or more services.
Restart-computer This cmdlet is used to restart the Windows operating system on local and
remote computers.
Resume-job This cmdlet is used to restart a suspended job.
Save-Help It is used to download and save the newest help files to a file system
directory.
Save-packages This cmdlet is used to save the packages to the local computer without
installing them.
Save-Script This cmdlet is used to save a script.
Select-string This cmdlet is used to find the text in string or files.
Send-MailMessage This cmdlet is used to send an e-mail message.
Set-Alias This cmdlet creates or changes the alias for a cmdlet in the current
Windows PowerShell.
Set-content This cmdlet writes the content in a file.
Set-Date This cmdlet changes the time of the system.
Set-Item This cmdlet changes the value of an item to the value specified in the
command.
Set-ItemProperty This cmdlet change or creates the value of the property of an item.
Set-Location This cmdlet is used to set the current working location to a particular
location.
Set-PSBreakpoint This cmdlet sets a breakpoint on a command, line or a variable.
Set-ScheduledJob This cmdlet changes the scheduled Job.
Set-Service This cmdlet stops, start and suspend services, and changes its properties.
Set-variable This cmdlet sets the value of the variable.
Show-command This cmdlet creates the Windows PowerShell commands in a graphical
command Window.
Sort-Object This cmdlet sorts the object by the property value.
Start-Job This cmdlet starts a background job of Windows PowerShell.
Start-Process This cmdlet starts on or more process on a local computer.
Start-services This cmdlet starts one or more services which are stopped.
Start-transaction This cmdlet starts a transaction.
Stop-Computer This cmdlet shut down the local and remote computers.
Stop-Job This cmdlet stops a background job of Windows PowerShell.
Stop-Process This cmdlet stops one or more processes.
Stop-Services This cmdlet stops one or more running services.
Suspend-jobs This cmdlet temporarily stops the workflow jobs.
Suspend-Service This cmdlet suspends or pauses one or more running services.
Undo-transaction This cmdlet rollbacks the active transaction.
Uninstall-module This cmdlet is used to uninstall a module.
Uninstall-Package This cmdlet uninstalls one or more packages of software.
Unregister-ScheduledJob This cmdlet deletes the scheduled jobs on the local computer
Update-Help This cmdlet is used to download and installs the newest help files on the
computer.
Write-Output This cmdlet sends the particular object down the pipeline to the next
command.
=: Microsoft, Whatls
The Tech Platform
Comments