• PowerShell check if file contains string
    14 April

    PowerShell Check If File Contains String

    Using Select-String Cmdlet Use the Select-String cmdlet to check if the specified file contains the given string in PowerShell. [crayon-662f1d81157ad903448030/] [crayon-662f1d81157b6858104720/] First, we declared and initialized a variable named $path containing the location of the file1.txt file. Then, we created another variable called $string and set its value with "customers"; this is the value we […]

  • PowerShell convert epoch time to DateTime
    14 April

    PowerShell Convert Epoch Time to DateTime

    Before moving towards various solutions to convert the Epoch time to Datetime, it is essential to know the Epoch time. Epoch time, POSIX time or Unix time is the system for denoting a point in time to a single number. This single number is the number of seconds (not counting leap seconds) that have elapsed […]

  • Powershell convert Guid to String
    14 April

    PowerShell Convert Guid to String

    💡TL;DR Use the ToString() method on System.Guid to convert a GUID to a string in PowerShell. [crayon-662f1d8116826995250055/] [crayon-662f1d811682d832819416/] Before diving into the solutions, let’s understand what GUID is. In PowerShell, a Globally Unique Identifier (GUID) is a 128-bit identifier used to identify objects uniquely—for instance, folders, files, registry keys, and other system resources. Remember, GUIDs […]

  • Generate random String in PowerShell
    10 April

    Generate Random String in PowerShell

    Using [System.Guid] Class To generate a random string in PowerShell: Create a globally unique identifier using the NewGuid() method. Use the ToString() method to transform the GUID (created in the previous step) to String format. Use the Write-Host cmdlet to print the random string. [crayon-662f1d8116ed2791827738/] [crayon-662f1d8116ed9810756806/] The New-Guid() is a static method of [System.Guid] class […]

  • Mandatory Parameters in PowerShell
    10 April

    Mandatory Parameters in PowerShell

    Using Mandatory Attribute Use the Mandatory attribute to make parameters mandatory in PowerShell. [crayon-662f1d811755f893125879/] [crayon-662f1d8117565157295443/] First, we defined a function named DisplayName preceded by the function keyword. Inside this function, we used the param keyword (also referred to as param() block), which was used to define the $Name parameter; this parameter was of the string […]

  • Get yesterday's date in PowerShell
    09 April

    Get Yesterday’s Date in PowerShell

    Using Get-Date Command with AddDays() method Use the Get -Date command with AddDays() method to get yesterday’s date in PowerShell. Pass -1 to AddDays() to substract one day from current date and time [crayon-662f1d8117cff778341576/] [crayon-662f1d8117d04384205959/] The simplest way to get yesterday’s date in PowerShell is by using the Get-Date cmdlet with AddDays() method. For example, […]

  • Get all files in directory reclusively in PowerShell
    09 April

    Get All Files in Directory Recursively in PowerShell

    In PowerShell, the directory can be retrieved recursively using the Get-ChildItem cmdlet and the -Recurse parameter. [crayon-662f1d81181ff569770856/] [crayon-662f1d8118203728086384/] If you are looking to get all files in current directory in PowerShell, you can use below command: [crayon-662f1d8118204699342231/] The folders and files can also be excluded using the -Exclude parameter. First, have a look at the […]

  • Get Full path of file in PowerShell
    07 April

    PowerShell- Get Full Path of File

    Get Full Path of File in PowerShell To get full path of file in powershell: Go to folder where file is present. You can go to any parent folder as well. Use Get-ChildItem with -Recurse option. Pipe it to where-object cmdlet to filter filename. In this example, we have given filename as test.ps1 Pipe it […]

  • PowerShell - get Permissions on folder and subfolders
    07 April

    PowerShell – Get Permissions on Folder and Subfolders

    To understand how to get permissions on a folder and subfolder in PowerShell, you must first understand what folder and subfolder permissions are. A folder’s permissions establish who can access and modify files and folders. A subfolder permission is a permission set for a folder containing other folders. In general, permissions set on a folder […]