Chirag Nagrekar has Published 465 Answers

How to write Progress Bar in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 15-May-2020 13:03:20

When we write a script in PowerShell, users who execute it, expect to see the progress of the script instead of waiting idle and looking at the blank cursor while the script is executing the background task. One way to achieve is to use the Verbose parameter to see the ... Read More

How to remove empty string/lines from PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 15-May-2020 12:57:43

In many instances, you need to remove empty lines or strings from the PowerShell string array or the files. In this article instead of removing empty string, we will get the result or filter the output from lines that are not empty. In this way, we can get the output ... Read More

How to get the port number of the processes using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 04-May-2020 13:22:15

When we use Get-Process cmdlet in PowerShell, it doesn’t have properties to get Port number the processes use. So here we will write a function that will provide us the ports number associated with the processes.There is one windows command NETSTAT which provides the Port number and the associated process ... Read More

Explain ValueFromPipeline in PowerShell Advanced Functions.

Chirag Nagrekar

Chirag Nagrekar

Updated on 04-May-2020 07:15:45

Consider the below example, we have created Advanced function to get the specific process information like Process Name, Process ID (PID), Start Time, Responding status, etc.function Get-ProcessInformation{    [cmdletbinding()]    param(       [Parameter(Mandatory=$True)]       [string[]]$name    )    Begin{       Write-Verbose "Program started"   ... Read More

Explain AllowEmptyString() and AllowEmptyCollection() in PowerShell Advanced Function.

Chirag Nagrekar

Chirag Nagrekar

Updated on 04-May-2020 07:04:15

AllowEmptyString() attribute works with the string variable and AllowEmptyCollection() work with the array of different data types (Collection).Consider the example below. Here, we are using a mandatory variable $name which is a string and $stringarray which is a string array.function print_String{    [cmdletbinding()]    param(       [parameter(Mandatory=$True)]   ... Read More

Explain the Mandatory Attribute in PowerShell Advanced Function.

Chirag Nagrekar

Chirag Nagrekar

Updated on 04-May-2020 07:01:04

We have an example of PowerShell advanced function below and we will try to understand how mandatory parameter works.function math_Operation{    [cmdletbinding()]    param([int]$val1, [int]$val2)    Write-Host "Multiply : $($val1*$val2)"    Write-Host "Addition : $($val1+$val2)"    Write-Host "Subtraction : $($val1-$val2)"    Write-Host "Divide : $($val1+$val2)" }When you execute the above ... Read More

Explain the PowerShell Advanced Function.

Chirag Nagrekar

Chirag Nagrekar

Updated on 04-May-2020 06:56:58

Before starting the Advance PowerShell function, assuming we know about the PowerShell function. You can check the explanation on the PowerShell function below.https://www.tutorialspoint.com/explain-the-powershell-functionHere, we will take the math function example that calculates the different types of operations. We already have a code with the simple function as shown below.function math_Operation{ ... Read More

How to pass the parameters in the PowerShell function?

Chirag Nagrekar

Chirag Nagrekar

Updated on 17-Apr-2020 12:36:16

You can pass the parameters in the PowerShell function and to catch those parameters, you need to use the arguments. Generally, when you use variables outside the function, you really don’t need to pass the argument because the variable is itself a Public and can be accessible inside the function. ... Read More

Explain variable / Array scope in PowerShell function.

Chirag Nagrekar

Chirag Nagrekar

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

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

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

Advertisements