What Is Windows Powershell Used For
PowerShell is an object-oriented automation engine and scripting language with an interactive control-line shell that Microsoft adult to help Information technology professionals configure systems and automate administrative tasks.
PowerShell, built on the .NET framework, works with objects, whereas most control-line shells are based on text. PowerShell serves as an automation tool for system administrators, employed in both It departments and external entities, such as managed service providers, because of its scripting capabilities.
PowerShell originated as a propriety offering that was only bachelor on Windows. In 2016, Microsoft open sourced PowerShell and made it available on Linux and macOS.
What does PowerShell do?
Microsoft designed PowerShell to automate organisation tasks, such every bit batch processing, and to create organisation direction tools for commonly implemented processes. The PowerShell language, similar to Perl, offers several ways to automate tasks:
- with cmdlets, which are very small .Internet classes that appear as system commands;
- with scripts, which are combinations of cmdlets and associated logic;
- with executables, which are stand-lonely tools; and
- with the instantiation of standard .NET classes.
Admins tin can use PowerShell to handle a wide range of activities. It tin extract information on OSes, such every bit the specific version and service pack levels. "PowerShell providers" are programs that brand data contained in specialized data stores accessible at the command line. Those data stores include file organisation drives and Windows registries.
PowerShell also serves equally the replacement for Microsoft's Command Prompt, which dates back to DOS. Microsoft, for example, made PowerShell the default command-line interface (CLI) for Windows 10 equally of build 14791. PowerShell's role as a command-line vanquish is how nigh users become acquainted with the technology.
Central PowerShell features
Microsoft incorporates updates and new features with each PowerShell version, merely hither is a listing of the primary features and characteristics.
Discoverability. Users can discover PowerShell's features using cmdlets such every bit Become-Control, which creates a list of all the commands, including cmdlets and functions, bachelor on a given reckoner. Parameters tin can be used to narrow the telescopic of the search.
Assistance capabilities. Users can learn more about PowerShell principles and particular components such as cmdlets through the Get-Assist cmdlet. The -online parameter provides access to assist manufactures on the spider web, if available for a particular topic.
Remote commands. Admins tin perform remote operations on i or multiple computers, taking advantage of technologies such as Windows Management Instrumentation and WS-Management. The WS-Direction protocol, for example, lets users run PowerShell commands and scripts on remote computers.
Pipelining. With PowerShell, commands tin be linked together through the pipe operator, symbolized as |. This approach lets the output from a given command become the input for the side by side command in the pipeline sequence. The PowerShell pipeline lets objects, rather than text strings, catamenia from one cmdlet to another.
Details on additional features can be establish in the following sections.
Desired State Configuration
With PowerShell 4.0, Microsoft introduced a configuration management platform called Desired Country Configuration (DSC), which admins can utilize to gear up a specific configuration for a server. After the admin defines the server settings, PowerShell ensures the target nodes retain that desired state. DSC has 2 modes of operation: push way and pull mode.
In push fashion, a server sends notifications to the nodes. It's a one-way advice, where the admin sends notifications from a workstation. Setup costs are less because management runs from a device, but a notification gets lost if the device isn't connected to the network.
In push mode, the IT department creates a pull server with the configuration details of each node using an MOF file. Each node contacts the pull server to bank check for a new configuration. If the new configuration is available, the pull server sends the configuration to the node. Admins can manage all devices regardless of their network connection. When a device connects to the network, it automatically contacts the pull server to check for a new configuration.
DSC resources
DSC resources are the components of a configuration script. Admins tin can check the available DSC resource on a machine with the Get-DscResource control.
Admins use these resources to configure components such every bit registry keys and Windows services or to create and manage local users through a configuration script. For instance, the File resource manages files and folders, the Environment resource manages environment variables and the Registry resource manages the registry keys of a node.
PowerShell Integrated Scripting Surround
PowerShell Integrated Scripting Environment (ISE), introduced past Microsoft in PowerShell version 2.0, is a PowerShell host application used to write, test and debug scripts or write commands in a Windows graphical user interface (GUI).
PowerShell ISE comes with multiple features, such as syntax coloring, multiline editing, context-sensitive assist and tab completion.
PowerShell ISE has sophisticated features that are familiar to Windows users. For instance, a user can highlight and re-create a portion of a PowerShell command with a mouse or with the Shift + Arrow hotkey combination. The user can also paste the content anywhere in the editor window.
Another useful feature is the ability to continue different versions of a command in the editor and run commands yous need in the PowerShell ISE.
The F5 key launches a control directly from the editor. To execute a particular line, select information technology and press F8. The context-sensitive assistance displays matching cmdlets when the user starts to enter a control. A command addition shows a list of cmdlets to select.
PowerShell ISE provides tabs to enable work on multiple administrative tasks. PowerShell ISE enables quick switching from the CLI to scripting way.
PowerShell modules
PowerShell modules enable admins to reuse a script to automate a job. A PowerShell module tin be divers as a set of PowerShell functions that are grouped to manage all the aspects of a particular area. PowerShell modules enable admins to reference, load, persist and share code. The simplest way to create a PowerShell module is to save the script as a PSM1 file.
A PowerShell module contains four essential elements:
- a PSM file, which is the module;
- help files or scripts needed by the module;
- a manifest file that describes the module; and
- a directory that stores the content.
A PowerShell module tin can be i of iv types:
- Script module: A PSM1 file that contains various functions to enable admins to perform import, consign and management functions.
- Binary module: A .NET framework assembly (DLL file) that contains compiled lawmaking. Developers typically use a binary module to create cmdlets with powerful features not easily done with a PowerShell script.
- Manifest module: A manifest module is a module (PSM1) file with an associated PSD1 file (manifest).
- Dynamic module: A dynamic module is created dynamically on demand past a script. Information technology isn't stored or loaded to persistent storage.
PowerShell functions
A PowerShell part is similar to a PowerShell cmdlet, with several slight differences. Cmdlets are written in a compiled .NET language, such as C#, while functions are written in PowerShell and aren't compiled.
For developers and independent software vendors, it'due south easier to parcel and deploy a PowerShell cmdlet compared to packaging libraries of functions. Cmdlets and advanced functions support powerful parameter bindings.
By describing a parameter to the shell, admins can use whatsoever type of PowerShell parameters, such equally named parameters, mandatory parameters and positional PowerShell parameters.
An example of a PowerShell function is:
function Set-Something {
[CmdletBinding()]
param (
[Parameter()]
[cord]$Thing
) Write-Host $Affair
}
A office contains one or more option parameters within of a parameter block and a body.
Language constructs
Every bit a scripting language, PowerShell offers several language constructs that control the flow of scripts, while making decisions as to what should be done. Some of the language constructs include conditionals, switches, loops and variables.
Conditionals. The language construct if is used to evaluate a conditional expression. When the conditional expression is truthful, a script block is executed.
if ($i -eq one)
{
## Do something
}
else
{
## Do something else
}
Switch. The switch statement is used when at that place is a long list of conditional statements to test. Switch is commonly used in place of many if/so/else constructs.
switch ($i) {
0
{
Write-Host "I is 0"
}
1
{
Write-Host "I is 0"
}
Default
{
Write-Host "I is not 0 or i"
}
} Loops. The while statement repeats code as long every bit the following provisional expression is true:
while ($i -eq 0) {
## Do somthing
} The do loop is similar to the while loop. The but difference is PowerShell executes the do loop at the cease of the loop.
do {
## do something
} while ($i -lt 0) When you use a foreach loop, PowerShell repeats the code for each item mentioned in the script.
$array = ('item1','item2','item3')
foreach ($item in $array) {
$item
} Employ a for loop to execute statements repeatedly until a status is met.
for ($i = 0; $i -lt 5; $i++)
{
$i
}
Variables
Variables shop data, but PowerShell variables are more powerful considering they can exist mapped to underlying classes in the .NET framework. PowerShell treats variables as .Net objects, which ways they can store data and manipulate data in multiple ways.
Variable names in PowerShell start with a dollar sign and incorporate a mix of numbers, letters, symbols and spaces. For instance, $var="HELLO" stores the string HELLO in the $var variable. Variables tin can also have different scopes, such as global, local, script, individual and numbered scopes.
Arrays
A PowerShell array is a component that enables the storage of more one item in a variable or a field. For case, to assign multiple values to a variable, apply the post-obit script:
$a=1,2,3
PowerShell treats each detail in an array as a carve up element. To address each item in an assortment, PowerShell offers alphabetize numbers. The first chemical element in the assortment is indexed equally 0 by default. The biggest advantage of PowerShell is that it automatically handles array insertions, so arrays don't have to be manually destroyed or created when calculation or removing elements.
Hash tables
Hash tables are data structures like to arrays. A PowerShell array stores multiple unmarried items, only with a hash tabular array, each item or value is stored using a key or value pair. An array can't shop multiple values under each element, while a hash table can.
Below is an example comparing an assortment with a hash table:
$array = @('Joe','Susie','Donnie')
$hashtable = @{FirstName = 'Joe'; FirstName = 'Susie'; FirstName = 'Donnie'} Help and comments
PowerShell enables the improver of assist topics for modules, scripts and individual commands. To view all the assistance topics, apply the Get-Help command.
When importing a module into a session, PowerShell automatically imports the help topics for that module. If there are no assist topics for a module, the Get-Help command displays autogenerated help. Three types of assistance content be in PowerShell: comment-based assist, external assist and updatable assist.
Comment-based assistance refers to comments included with a script or command for Get-Assistance to read. External help enables the author to ascertain assistance content in an external XML file written in XAML. Updatable assist uses external assistance but enables users to download the latest help content with the Update-Help command.
Executable programs
PowerShell is also a cmd.exe replacement that runs an executable program in multiple ways through the Offset-Process command, the ampersand and the Invoke-Expression command. Using ping.exe as an example, here's how a user tin run the executable plan using PowerShell:
Start-Procedure -FilePath 'ping.exe' -ArgumentList 'google.com' -Wait -NoNewWindow
& 'ping.exe' google.com
ping google.com
Invoke-Expression -Control 'ping.exe google.com'
What Is Windows Powershell Used For,
Source: https://www.techtarget.com/searchwindowsserver/definition/PowerShell
Posted by: holtonthentand.blogspot.com

0 Response to "What Is Windows Powershell Used For"
Post a Comment