PowerShell logo

What Is PowerShell ?

Random Technology

What Is PowerShell ?

What is PowerShell?

PowerShell is a command-line interface that can be used for task automation and the creation of management tools for most commonly implemented processes. For the inner geeks out there, it’s made up of a command-line shell and a scripting language based upon the.NET Framework. But what is its purpose I hear you ask. Well, it’s for making repetitive tasks easier you can run them with commands, automate them as well as making complex tasks less complex by wrapping several commands into one. Administration can also be done on local devices as well as remote computers and systems running Linux as well!

As mentioned earlier the PowerShell environment uses the .NET framework and so upon running an action from the console window you will receive a .NET Framework object back. This doesn’t mean however that they won’t play nicely with any other commands, PowerShell can also be tied into running scripts and executables as well.

In order to administer task, PowerShell can run four kinds of commands
– Cmdlets; which are lightweight commands that perform a specific function.

– PowerShell scripts; which can be written within PowerShell or the Integrated Scripting Environment (ISE), these carry the .ps1 extension.

– PowerShell Functions

– Standalone executable programs
If a command is a standalone program, then PowerShell will run this as a new separate process. Cmdlets are ran using the PowerShell process and are normally constructed of a verb and a noun. Microsoft has created a tool which can create scripts for you using cmdlets. It’s called the Windows PowerShell Command Builder.

Your favourite CMD commands can also be run in PowerShell, meaning you can do all of your configuration and administration in one command line facility rather than multiple sessions open. PowerShell can even be loaded into Command Prompt by typing PowerShell and then this will load up a PowerShell session within your command prompt window for you.

PowerShell

 

Above you can see a PowerShell command window open with a command input and the output from that command. The command itself Get-Process will list all of the running processes running on the system you specified. This command is split into two meanings, the first logical part “Get” is what you want PowerShell to do, you want it to go and get you something. The second part, “Process” is the item you want PowerShell to get and retrieve back to you.

PowerShell also has add-ons that can be imported into PowerShell sessions, these can be used if you need to share code with others, if it needs to be used more than one, or if it’s for a specific program (such as VMware). To put it simply modules are a group of functions and code that are based around a centralised theme. They can also be created for Print Management and network adapter configurations etc.

If I run this command in PowerShell now I will receive the following

C:\Users\Lucidica> Get-Module -Name posh-ssh

C:\Users\Lucidica>

Absolutely nothing! This is because you are trying to call a module that PowerShell cannot find, in order to import a module into your PowerShell Session you need to set type to import and specify the location and the module name then you’re good to go!

C:\Users\Lucidica> Import-Module \\server\powershell\poshssh.psm1

The module is only imported for the sessions that you are currently using if it needs to be accessed often then the Module should be placed in the PsModulepath folder so that it automatically loads next time it is needed.

PowerShell ISE (Integrated Scripting Environment) is a graphical user interface, used for an easier way to create scripts and being able to test them. Essentially it is a Command windows for running interactive commands through

The ISE also includes a script pane for creating, editing and also running your scripts. From here you are able to see the whole script and are able to highlight certain parts from it. You are able to see the outputs of a script much more easily and can see if there are any errors which are causing your script to fail. You can also Tab your command windows to a single environment, meaning that it’s easy to switch back and forth from different script sessions you have open. A built-in Debugger is also included for debugging commands, functions, and scripts. You can, of course, customise the layout, colour of the text and background etc as well.

Below is a screenshot of a script being created in the ISE for the creation of a Local Admin account, when the script is run, an output will appear in the bottom box.

PowerShell