Basic of PowerShell-Part 1
PowerShell is a scripting language. It helps to automate the technical tasks like generate daily client reports. Going to start a series of blogs to share the basic understanding of PowerShell for the beginners. This is the Part-1 in which we will cover the below given points.
1- Define the variable- $ is used to define the variable
2- Comment the single line- # is used to comment the single line
3- Comment the Multiple lines- <# content #> is used to comment the multiple lines
4- Use of Write-Host- Write-host is used to print the outcome or print the any message
5- Use of Read-Host- Read-host is used to take run time input from the User. it returns the datatype string.
6- Covert the datatype- To convert the datatype, use syntax like [Int]$stringvaribale. it will convert the string value into the int.
To understand the above, we will take a example of 'Add two numbers'.
PowerShell Script-1
#write the PowerShell script to add the number
#Add the two numbers
<#write the PowerShell script to add the number
Add the two numbers#>
#define the variable
$num1= 5
$num2= 6
$TotalSum = $num1 + $num2
Write-Host 'Total Sum:'$TotalSum'
Output of this script- Total Sum: 11
PowerShell Script-2
# use of Read-Host and Convert the variable into Int
$num1= Read-Host 'Inter the First Number'
$num2= Read-Host 'Inter the Second Number'
$TotalSum = [Int]$num1 + [Int]$num2
Write-Host 'Total Sum:$TotalSum'
Output of this script- User need to inter first number and second number at runtime.
Comments
Post a Comment