• Create Empty File in PowerShell
    28 December

    Create Empty File in PowerShell

    Using New-Item Cmdlet Use the New-Item cmdlet to create an empty .txt file in PowerShell. [crayon-664036df847b7262505545/] [crayon-664036df847bf952494564/] We used the New-Item cmdlet with -Path, -Name, and -ItemType parameters to create an empty .txt file using Windows PowerShell. Let’s break down the above command to understand it more clearly. The New-Item cmdlet creates a new item […]

  • 27 December

    Run PowerShell as Another User

    Using the runas Command The runas command in PowerShell launches programs using credentials different from the current user. It provides users with limited privileges to execute commands or access resources available only to more privileged accounts. The command’s syntax is runas /user:UserName ProgramName where UserName is an account with permission and ProgramName is the name […]

  • 26 December

    Concatenate String in PowerShell

    Using Operators To concatenate string in PowerShell: Declare and initialize variables which contain string-type values. Use +, -f, and -join operators to concatenate values of all variables we created in the first step. [crayon-664036df8531d899658190/] [crayon-664036df85323737434315/] We can use the +, -f, and -join operators to concatenate strings with/without separators in PowerShell. Let’s understand the use […]

  • 26 December

    Remove Duplicates from Array in PowerShell

    Using Select-Object with the -Unique Parameter To remove duplicates from array in PowerShell: Use the array operator to create an array having duplicate values. Use the Select-Object with the -Unique parameter to select unique values from the array we created in the previous step. [crayon-664036df85a41628171871/] [crayon-664036df85a47372140106/] For this code, we used the array operator (@()) […]

  • 24 December

    Get AD User Description in PowerShell

    To get AD user description in powerShell, use Get-AdUser cmdlet with -Properties as Description. [crayon-664036df8614c021994798/] Please note that you must must first install the Remote Server Administration Tools (RSAT) package and import the Active Directory module. Get AD User Description and Attributes in PowerShell The Get-ADUser cmdlet is a powerful tool in the Active Directory […]

  • 24 December

    Create Folder If Not Exist in PowerShell

    This tutorial will explain how to create a folder using PowerShell if it does not exist in the given location. Using Test-Path and New-Item Cmdlets To create folder if not exist in PowerShell: Use Test-Path cmdlet with if statement to check the path. If folder doesn’t exist, Create a new folder with New-Item cmdlet. [crayon-664036df86290245633398/] […]

  • 24 December

    Check If String Contains Substring in PowerShell

    1. Overview In PowerShell scripting, a common requirement is to check whether a string contains a specific substring. This is a fundamental task in text processing, often used in conditional logic, data validation, or filtering operations. In this article, we will see different ways to check if string contains substring using various methods such as […]

  • 24 December

    Delete File If Exists in PowerShell

    This tutorial will discuss how to delete a file if it exists using PowerShell. Delete File If Exists in PowerShell To delete a file if exists in PowerShell: Use Test-Path cmdlet with if statement to check if file exists at given location. If files exists, use Remove-Item cmdlet to remove the file at given location. […]

  • 16 December

    Run CMD Command in PowerShell

    1. Introduction PowerShell, a powerful scripting and automation tool by Microsoft, is often used for its advanced features and flexibility. However, there are scenarios where it is necessary to run traditional Command Prompt (CMD) commands within PowerShell. This necessity may arise due to specific CMD functionalities, integration with legacy systems, or compatibility reasons. In such […]