Powershell is one of command shell alternative for handling command line based operations and scripting.
Powershell is based on .NET Framework. It has nearly all the features available in other .NET Framework related programming languages.
Powershell command line
Powershell is based on .NET Framework. It has nearly all the features available in other .NET Framework related programming languages.
Powershell was initially named as Monad, but it was later named as Powershell.
The programming style of Powershell is similar to Perl and Korn shell and similar to C# or VB.NET.
Powershell can be used in Windows Core installation for administrative purposes.
How to install Powershell?
Installation of Powershell is not required for Windows 2008 and Windows 7..
To check if Powershell is installed-
1. Goto Start > Run.
2. Type cmd to open command prompt.
3. Type below command -
where powershell
If Powershell is not installed, you will get below output-
INFO: Could not find files for the given pattern(s).
You may install the version 1 or version 2 of Powershell based on the machine type and operating system. Please google and find the link, I am skipping providing link as it might change in future.
Powershell command line
Powershell command line is nearly the same as Command prompt. However, it looks bit different in background color which is blue by default.
Hello world!
This is simple to just write Hello world! Just type in below command -
echo Hello world!
But, I will write a script for the same which will have an argument.
Writing your first script in Powershell:
1. Powershell script must be a script with *.ps1 extension.
2. Your execution policy must be set correctly. I will discuss about execution-policy later, but for now, set to unrestricted to run your first script using below command.
set-executionpolicy Unrestricted;
3. Write the script as mentioned below -
function HelloWorld([string] $useInput)
{
echo $userInput;
}
HelloWorld $args[0];
4. Save the script. I assume your named helloworld.ps1.
5. Run the script
From Powershell command-line:
.\helloworld.ps1
Use .\ when the script is located on the same directory (present working directory)
You may also write the complete path.
From Command prompt:
Powershell D:\helloworld.ps1
Points to remember :
1. The file extension must be .ps1
2. Powershell execution policy must be set appropriately to run the script on a given machine.
3. You cannot double click the powershell script similar to batch programs.
4. A Powershell script run under .NET Framework. It can include all the libraries which C# or VB.NET can utilize.
echo Hello world!
But, I will write a script for the same which will have an argument.
Writing your first script in Powershell:
1. Powershell script must be a script with *.ps1 extension.
2. Your execution policy must be set correctly. I will discuss about execution-policy later, but for now, set to unrestricted to run your first script using below command.
set-executionpolicy Unrestricted;
3. Write the script as mentioned below -
function HelloWorld([string] $useInput)
{
echo $userInput;
}
HelloWorld $args[0];
4. Save the script. I assume your named helloworld.ps1.
5. Run the script
From Powershell command-line:
.\helloworld.ps1
Use .\ when the script is located on the same directory (present working directory)
You may also write the complete path.
From Command prompt:
Powershell D:\helloworld.ps1
Points to remember :
1. The file extension must be .ps1
2. Powershell execution policy must be set appropriately to run the script on a given machine.
3. You cannot double click the powershell script similar to batch programs.
4. A Powershell script run under .NET Framework. It can include all the libraries which C# or VB.NET can utilize.
No comments:
Post a Comment