Chirag Nagrekar has Published 465 Articles

Explain variable / Array scope in PowerShell function.

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-Apr-2020 12:34:31

216 Views

Generally, when the variable is declared as a Public variable or outside the function in the script (not in any other variable or condition), you don’t need to pass that value to function because the function retains the value of the variable when the variable is initialized before the function ... Read More

Explain the PowerShell Function.

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-Apr-2020 12:32:23

767 Views

Function in a PowerShell is to reduce the redundancy of the repeated codes this means codes which are repeating, bind them into a function and call the function whenever necessary, so you don’t need to write codes multiple times.ExampleLet assume, you want to perform arithmetic operations (multiply, sum, divide and ... Read More

How to sort the output in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 07-Apr-2020 12:25:24

10K+ Views

To sort the output in the PowerShell you need to use Sort-Object Pipeline cmdlet. In the below example, we will retrieve the output from the Get-Process command and we will sort the, according to memory and CPU usage.ExampleGet-Process | Sort-Object WorkingSet | Select -First 10OutputHandles  NPM(K)    PM(K)     ... Read More

How to use Measure-Object in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 07-Apr-2020 12:21:33

2K+ Views

Measure-Object in PowerShell is used to measure the property of the command. There are various measurement parameters are available. For example, Average, Count, sum, maximum, minimum and more.ExampleGet-Process | Measure-ObjectOutputPS C:\WINDOWS\system32> Get-Process | Measure-Object Count       : 278 Average     : Sum         : ... Read More

How to use Group-Object cmdlet in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 07-Apr-2020 12:18:10

630 Views

As the name suggests, Group-Object is useful to group similar properties.ExampleGet-Service | Group-Object StatusOutputCount Name          Group ----- ----          ----- 160 Stopped         {AarSvc_8f3023, AdobeFlashPlayerUpdateSvc, AJR outer, ALG...} 130 Running         {AdobeARMservice, Appinfo, AudioEndpointBuilder, Audiosrv...}The above output ... Read More

How to check the PowerShell version installed in local and remote systems?

Chirag Nagrekar

Chirag Nagrekar

Updated on 07-Apr-2020 11:58:36

2K+ Views

To check the PowerShell version installed in your system, you can use either $PSVersionTable or $host command.Check if $host command available in remote servers.Open the PowerShell console in the system and run the command $PSVersionTable.$PSVersionTableOutputPS C:\WINDOWS\system32> $PSVersionTable Name                         ... Read More

How to edit the CSV file using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 26-Mar-2020 07:32:48

6K+ Views

To edit the CSV file using PowerShell, you need to use the below commands.We already have the CSV file output.csv, we will import this file first.$csvfile = Import-csv C:\temp\Outfile.csvOutputBelow is the output of the CSV file.EMP_Name    EMP_ID     CITY --------    ------     ---- Charles     ... Read More

How to append data into a CSV file using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 26-Mar-2020 07:28:05

36K+ Views

To append the data into CSV file you need to use –Append parameter while exporting to the CSV file.In the below example, we have created a CSV fileExample$outfile = "C:\temp\Outfile.csv" $newcsv = {} | Select "EMP_Name", "EMP_ID", "CITY" | Export-Csv $outfile $csvfile = Import-Csv $outfile $csvfile.Emp_Name = "Charles" $csvfile.EMP_ID = "2000" ... Read More

How to create a CSV file manually in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 26-Mar-2020 07:23:52

4K+ Views

There are few methods to create a CSV file in the PowerShell, but we will use the best easy method to create it.First, to create a CSV file in PowerShell, we need to create headers for it. But before it, we need output file name along with its path.$outfile = ... Read More

How to Export and import CSV file manually in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 26-Mar-2020 07:19:32

1K+ Views

When you run a command Export-Csv in PowerShell, it automatically creates a CSV file to the specific location.ExampleGet-Service | Select Name, Starttype, Status | Export-Csv C:\temp\services.csv -NoTypeInformationIn the above example, Services.csv file created in C:\Temp folders with the header Name, Starttype, and Status headers.Similarly, you can use the other commands ... Read More

Advertisements