• Wait for Command to Finish in PowerShell
    13 March

    Wait for Command to Finish in PowerShell

    Using Start-Process Cmdlet Use Start-Process with the -Wait parameter to wait for the command to finish. [crayon-6643298707e26673603846/] OUTPUT: In the above output, we can see that the command waits until the file explorer is opened. To do that, we used Start-Process with the -Wait parameter. The Start-Process cmdlet is used to start one or multiple […]

  • Check if Array contains element in PowerShell
    13 March

    Check if Array Contains Element in PowerShell

    1. Overview In this article, we will see different ways to check if array contains element in PowerShell using -contains operator, Contains() method, Where-Object cmdlet, -in operator, indexOf() method, and LINQ. 2. Introduction to Problem Statement We are given an array and element. Our goal is to check if array contains the element. For instance, […]

  • Download File from URL in PowerShell
    13 March

    Download File from URL in PowerShell

    Using Invoke-WebRequest Cmdlet Use the Invoke-WebRequest cmdlet to download the specified file from the specified URL to the local path in your machine. [crayon-6643298709ca5277819615/] First, we created two variables named $URL and $LocalPath containing a URL and the local path of your machine. Note that variables are prefixed with the $ sign in PowerShell. Next, […]

  • Delete Files older than X days in PowerShell
    11 March

    Delete Files Older than X Days in PowerShell

    Delete Files Older than X Days in PowerShell Use Remove-Item cmdlet with the Get-ChildItem cmdlet and Where-Object cmdlet to delete files older than X days. [crayon-664329870a478229213034/] The above script retrieved all the items from the given path, filtered them based on the specified property and kept only those files/folders that were less than the given […]

  • Ping List of Computers in PowerShell
    10 March

    Ping List of Computers in PowerShell

    Different Ways to Ping a List of Computers in PowerShell There are multiple ways that we can use to ping a list of computers in PowerShell. Now, what does ping means? Pinging a computer means determining if the networked computer is available and responsive. If the networked computer (we can also call it a target […]

  • Convert Array Object to String in PowerShell
    10 March

    PowerShell Array to String

    Using Double Quotation Marks Use double quotation marks to convert array object to string in PowerShell. [crayon-664329870b45a034831894/] [crayon-664329870b461434896948/] First, we created an array object and saved it in the $arrayObject variable; we can also create an array object using the array operator (@()), for instance, $arrayObject = @("How", "are", "you?"). Next, we enclosed the $arrayObject […]

  • Return value from function in PowerShell
    08 March

    Return Value from Function in PowerShell

    Using the return Keyword PowerShell allows us to use the return keyword to return single or multiple values from a function. Let’s learn both of the scenarios. Use the return Keyword to Return a Single Value To return a single value from a particular function: Create a function that returns something, a string, a number […]

  • Check if String is null or empty in PowerShell
    08 March

    Check if String is Null or Empty in PowerShell

    Using -not and -eq Operators Use the -not operator to check if the string is null or empty in PowerShell. [crayon-664329870c8ee848694268/] [crayon-664329870c8f1985495373/] First, we declared the $string variable and initialized it with $null. What is $null? It is an automatic variable in PowerShell representing the NULL value. Now, what is NULL? We can think of […]

  • Convert String to Int in PowerShell
    08 March

    Convert String to Int in PowerShell

    Using Dynamic Casting Use dynamic casting to convert the given string to int in PowerShell. [crayon-664329870dab5952004936/] [crayon-664329870dabc302274594/] First, we created and initialized a $string variable; then, we specified the type as [int] before the string variable to do dynamic casting. In dynamic casting, we tell the compiler to think about things differently. To cross-check, we […]