Windows PowerShell's Built-in CmdletsWindows PowerShell's - Build-in CmdletsOn this page I define the word cmdlet to mean a built-in PowerShell command, with a single verb-noun pair. There is another shade of meaning to cmdlet, namely a series of commands, usually more than one line, stored in a text file with a .ps1 extension. This page deals with the first meaning and includes a review of PowerShell's built-in cmdlets. Here are the 13 sections of PowerShell's built-in cmdlets.
PowerShell Build-in Cmdlet Categories1) System Built-in Cmdletsa) get-help. This
is the best command to explore the built-in PowerShell library. As with many cmdlets, it begins with the verb 'get'. Example: get-help
alias. Remember that get-help supports wildcards,
for example type: b) get-command. Returns a list of available commands. Get-command really is the entire command, I was expecting more, but this cmdlet is only two words, get and command separated by a hyphen. You may wish to try a wild card, for example get-command c* c) get-host. Displays information about the PowerShell host. (Not to be confused with hostname.) Try this command to check your version number. d) get-culture. Shows you information about the regional settings of the host (as defined in the Regional Settings of the Control Panel) e) get-uiculture Returns information about the regional settings of the host as defined by the selected language on a multi-language operating system. See more about key system cmdlets here 2) Objects Built-in Cmdletsa) get-Member. This is by far the most important cmdlet. get-Member enumerates properties, methods and type information of the objects; for example: get-WmiObject | get-Member b) foreach-object. The purpose of this cmdlet is to loop through multiple instances, such as disk drives. Foreach applies a block of script to each object in the pipeline. For example; $Nic=
get-WmiObject
Win32_NetworkAdapterConfiguration Note that the type of bracket is significant, () or {} each have a distinct role (condition) {script block}. Also note the + which not only adds numbers, but also is the same symbol that concatenates text. c) where-object (Often abbreviated to plain 'where') filters the input from the pipeline, allowing operation on only certain objects. For example: get-service | where-object {$_.status -eq "Stopped"} d) new-object. Creates instances of .NET or COM objects. New-object is particularly useful for creating VBScript objects. For example, network objects, Active Directory objects and also applications such as IE. e) select-object. Filters objects based on parameters set in the cmdlet command string f) group-Object. An undervalued cmdlet. Handy for collecting objects based on a common property value. g) sort-Object. Sequences object based on a property value 3) Items Built-in Cmdletsa) get-Childitem Retrieves the child items of the specified location(s), for example a list files in a folder b) get-Item Returns an object that represents an item in a namespace, for example get-Item .\* lists files in the current directory c) new-Item Creates a new item in a namespace, for example creates a sub-folder d) set-Item Sets the value of a pathname within a provider to the specified value e) remove-Item Deletes an item from a provider f) move-Item Transfers an item from one location to another, removing the original g) rename-Item Changes the name of an existing item h) copy-Item Copies an item from one location to another, leaving the original intact i) clear-Item Removes the content of an item j) invoke-Item Invokes an executable or opens a file k) get-acl Gets the access control list (ACL) associated with a file or item l) set-acl Sets the security ACL for an item or items
˚
4) Aliases Built-in PowerShell CmdletsUnderstanding Aliases is easy. Just start with the built-in Aliases, for example gci (get-Childitem). Also ft (format table) for example, get-Process * |ft name, handles, cpu -auto a) set-alias Maps an alias to a command, for example where you wish to create your own alias. b) get-alias Returns a list of all defined aliases c) new-alias Creates a new alias d) export-alias Outputs the system alias table in CSV format e) import-alias Updates the system alias table from a CSV file 5) Drives Built-in Cmdletsa) Get-psdrive Returns a list of all drives registered with cmdlet providers b) new-drive Creates a new drive associated with a cmdlet provider c) get-provider Returns a list of all registered cmdlet providers and the drives associated with each provider d) remove-drive Removes a drive association from a cmdlet provider 6) Paths and locationsa) get-location Displays the current location b) set-location Sets the current working location to a specified location (Has the Alias CD) c) combine-path Combines path elements into a single path d) convert-path Converts the path to the item given from an MSH path to a provider path e) parse-path Given an MSH path(s), streams a string with the qualifier, parent path, or leaf item f) test-path Returns true if the path exists, otherwise returns false g) resolve-path Resolves the wildcards in a path h) push-location Pushes a location to the stack i) pop-location Changes the current working location to the location specified by the last entry pushed onto the stack 7) Contents Built-in PowerShell Cmdletsa) add-content Appends content to a file or creates a file if one does not exist b) clear-content Removes content from a file while leaving the file intact c) get-content Returns the content of a file as a sequence of lines d) set-content Replaces the content of a file with new content 8) Access Operating System Componentsa) get-Process Returns a list of running system processes b) stop-process Terminates a running process c) get-service Returns a list of registered system services d) stop-service Terminates a running system service e) start-service Starts a stopped system service f) suspend-service Pauses a running system service g) resume-service Reactivates a paused system service h) restart-service Stops then restarts a system service i) set-service Configures the properties of a registered system service j) new-service Registers a new system service k) get-Eventlog Returns a list of event log entries from a specified event log l) get-WmiObject Returns data from WMI 9) Output Formatters Built-in Cmdletsa) out-file Sends output to a file b) out-printer Sends output to a printer c) out-string Sends output to a string d) out-null Drops all output e) out-default Sends output to the host; not called from the command line f) out-host Sends output to the host g) format-list Formats objects as a list of their properties displayed vertically h) format-Table Formats objects as a tabulated list (one line per object) i) format-wide Formats objects as a tabulated list (several objects per line) j) import-csv Generates a sequence of objects from a comma-separated variable file k) export-csv Writes a sequence of objects to a file in comma-separated form l) write-host Writes an object to the hosting environment (usually the console) m) write-progress Writes to the host's progress display channel n) write-object Writes an object to the pipeline o) write-debug Writes an object into the debug pipeline p) write-verbose Writes an object to the host's verbose display channel; output may or may not be shown depending on the host settings q) write-error Writes an object to the error pipeline r) read-host Reads data from the hosting environment (usually the console) 10) Variablesa) get-variable Returns the value of a variable b) new-variable Creates a new variable with a specified name and value c) set-variable Updates or creates a new variable with a specified name and value; useful at the end of a pipeline for storing objects into a variable for later use d) remove-variable Removes a variable definition from the variable list e) clear-variable Removes the value of a variable but leaves its definition in place ( i.e., sets its value to null) 11) Security Built-in Cmdletsa) get-pfxcertificate Returns an X509Certificate from a file b) get-credential Generates a credential by asking an interactive user to provide a password c) get-authenticodesignature Returns the Authenticode signature from a file d) set-authenticodesignature Updates the Authenticode signature on a file e) new-securestring Creates a string that can be used to safely store and work with sensitive information (e.g., passwords)f f) export-securestring Converts a secure string into an encrypted representation in a regular string g) import-securestring Converts an encrypted string back into a secure string 12) Miscellaneous PowerShell Built-in Cmdletsa) get-date Returns the current date and time b) set-date Updates the system date and time c) match-string Searches through a string or file(s) for a pattern d) measure-object Calculates arithmetical statistics on specific properties of pipeline objects e) new-timespan Calculates the time difference between two specified DateTime objects f) start-sleep Pauses processing for a specified number of seconds or milliseconds 13) Debugginga) set-mshdebug Enables/disables debugging and execution trace support b) trace-expression Enables tracing for a specified expression or command Result of get-commandTo get a complete list of all the Aliases, I went to the PS Prompt and typed: get-command | fw -column 3 Here are the results in three columns: (fw -column 3 means format the output in three columns.) Add-Content Add-History Add-Member Summary of PowerShell's Built-in cmdletsPowerShell has a rich source of built-in verb-noun pairs. While you probably only need about 20, it's worthwhile acquainting yourself with what commands are available. Guy says waste no opportunity to increase your cmdlet repertoire. See Also• Windows PowerShell Home • Introduction • Cmdlets • Exchange 2007 • Profile.ps1 • $_.Pipeline If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit. *
|
|||||