• 16 December

    Delete All Files in Directory in PowerShell

    This tutorial will discuss how to delete all files in a directory using PowerShell. Using Remove-Item cmdlet To delete all files in a directory: Use the Remove-Item cmdlet. Include asterisk symbol in the file path. [crayon-6640621242c26747834743/] The above command removes all content in the directory C:\test. If there are sub-directories in the location, it will […]

  • 16 December

    Write Array to CSV in PowerShell

    This article will explain how to write an array to a CSV file in PowerShell. Using the Export-Csv cmdlet The Export-Csv cmdlet in PowerShell creates a CSV file of the given objects. But you cannot directly write an array to a CSV file correctly. When you pipe the array to Export-Csv, the result will be […]

  • 08 December

    Add Property to Object in PowerShell

    Using Add-Member cmdlet The Add-Member cmdlet allows you to add members (properties and methods) to an object in PowerShell. To add property to a PowerShell object: Pipe an object to the Add-Member cmdlet followed by the property to add [crayon-6640621243c59470443227/] In the first command, Get-Item C:\test gets the DirectoryInfo object which is saved in a […]

  • 06 December

    Run Batch File from PowerShell

    In Windows PowerShell, we can run batch files in multiple ways. Running the batch file by specifying the absolute or relative path using the ampersand (&) operator: [crayon-66406212441f1331969467/] Running the batch file by using the Invoke-Expression cmdlet. This command works similarly with the ampersand operator (&), but we write it in PowerShell flavor. [crayon-66406212441f7185625870/] Running […]

  • 04 December

    Get Driver Versions in PowerShell

    Using win32_PnpSignedDriver class of the WMI object To get driver versions in PowerShell, use win32_PnpSignedDriver class of the WMI object. [crayon-66406212443cd856300764/] After running the command, your PowerShell should give you an output something like this: Note how the columns are arranged as Device Name, Device Version, and Description. If you are to write the command […]

  • 04 December

    Remove Empty Lines from File in PowerShell

    We can do several file operations using the PowerShell console. For example, creating a file, removing a file, copying and moving a file, displaying file content, etc. While working with files, you may encounter a situation where you need to delete blank lines in a file. This tutorial will show you how to remove empty […]

  • 30 November

    Check if Array is Empty in PowerShell

    1. Introduction In PowerShell, determining if an array is empty is a fundamental task often encountered in scripting. An "empty" array here refers to one that contains no elements. For example, given an array $myArray, our goal is to ascertain whether it’s empty and act accordingly. In this article, we will see different ways to […]

  • 29 November

    Get Length of String in PowerShell

    1. Overview In PowerShell scripting, a common requirement is to get the length of a string, which refers to the number of characters it contains. This operation is crucial in various scenarios, such as validating input, parsing data, or controlling flow in scripts. In this article, we will see different ways to get length of […]

  • 29 November

    Write Variable to File in PowerShell

    1. Introduction In PowerShell scripting, a common and critical task is writing data from variables to files. This process is integral in various scenarios like data export, logging, and configuration management. While our primary focus is on string variables, it’s crucial to address the handling of other data types, such as arrays, objects, or numbers. […]