Basic of PowerShell-Part2
PowerShell has amazing capability to extract the data into excel sheet, read the txt file, filter the data and convert the data into the table. By using these capabilities, "How can read the content and apply the filter on it" and "convert the data into table" these are the basic queries which today we will discuss in the blog in layman language by taken examples. this is part two of the Basic Of PowerShell series.
"How can read the content and apply the filter on it"-
Here, Let us take an example “.txt file has five company names which are like Infosys, Wipro, HCL, TCS and MPG. Apply the filter that is only fetch the record that is ‘Wipro’ ”.
Before Writing the script, We must think about the basic commands which we will use.
1- Get-Content – This command is used to read the data for a txt file.
2- Pipeline Operator ‘|’ - it will be used to run the multiple command in their sequence and pass the output from one command to another command which is in sequence.
Let's start the script writing-
Step-1 Create a txt file as i have created CompanyName.txt on my desktop. And add the above five names in different rows.
Step-2 Read this file by using
command Get-Content
Get-Content D:\Tutorial\CompanyName.txt
Step-3 Apply Filter and Use the Pipeline Operator
Get-Content D:\Tutorial\CompanyName.txt | Where-Object {$_.Equals('Wipro')}
Output of this single line PowerShell script- Wipro
Let us take an example ‘Get the today’s date and convert it into the table as well as list by using PowerShell’.
Get-Date command is used to fetch today's date from the System/ Server. And Format-Table is used to convert date into a table. by using these commands, data will be converted into the table.
Get-Date
Output-
Get-Date | Format-Table
Output-
Get-Date | Format-List
Output-
Comments
Post a Comment